How to send or pass multiple parameters in jquery ajax in asp.net

Posted by imomins on October 7, 2012 at 4:10 AM
Introduction:

Here I will explain how to send or pass multiple parameters using JQuery or JSON in asp.net.

Description:

In previous posts I explained articles relating JSON in that I explained how to call page methods using JSON or JQuery in asp.net or Auto complete textbox with JQuery/JSON in asp.net. Now I will explain how to pass or send multiple parameters using JQuery or JSON in asp.net.

If we want to send or pass multiple parameters using JSON or JQuery in asp.net we need to declare it like as shown below


$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "SaveAudiVideo.aspx/SaveData",
data: JSON.stringify({title: 'value1' ,songPath: 'value2' }),
dataType: "json",
success: function(data) {
$('lbltxt').text(data.d);
},
error: function(result) {
alert("error");
}
});
Here JSON.stringify is used to encode the parameters in JSON format and our webmethod will be like as shown below

C# Code

[WebMethod]
public static string SaveData(string title,string songPath)
{
string str = string.Empty;
return str;
}
VB.NET Code

<WebMethod()> _
Public Shared Function SaveData(ByVal title As String, ByVal songPath As String) As String
Dim str As String = String.Empty
Return str
End Function

Categories: AJAX, JQUERY, ASP.NET

Post a Comment

Oops!

Oops, you forgot something.

Oops!

The words you entered did not match the given text. Please try again.

You must be a member to comment on this page. Sign In or Register

0 Comments