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
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
2 comments :
hi suresh i have tried the same but it is not working for me...is there anyother thing i want to include in my project like asp.net ajax or JSON(newtonsoft json) ? my mail id is: karthikeyanmca42@gmail.com
i am trying this asp.net with jquery ajax for a long time. i understood the concepts but its not working for me .
thanks and regards
karthikeyan s (karthikeyanmca42@gmail.com)
How to pass values to String[] patameter
Note: Only a member of this blog may post a comment.