Here
I am going explain how to 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 in our aspx page under <script> tag.
Let's write a simple code to understand it.
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "SavecNetCode.aspx/SaveData",
data: JSON.stringify({title: 'value1' ,ID: '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 ID)
{
string str = ID+ title;
return str;
}:))
Great article, i just get very good jquery, i was looking for it from few days. Thanku for share this one with us.
ReplyDeleteVery useful script i have got, thanks
ReplyDeleteIt is really good to visit to your post guys as we can get new information about jquery, Thanks for this useful post.
ReplyDeleteIt is really good to visit to your post guys as we can get new information about jquery, Thanks for this wonderful post.
ReplyDeleteNice post, things explained in details. Thank You.
ReplyDeleteThis site definitely explains essential concepts to its readers. Thanks for sharing..
ReplyDeleteThanks a lot for writing this post.Thanks a lot for sharing. Keep blogging.
ReplyDeleteI believe that what I just read is some good material. Thanks for continuing to write such wonderful articles. God bless.
ReplyDeleteExtremely good article! I m a usual website visitor (very much like addict :P) to your website. Keep up the fantastic work .
ReplyDeleteVery informative, keep posting such good articles, it really helps to know about things :)
ReplyDeleteI guess I am not the only one having all the enjoyment here! Keep up the good work..
ReplyDeleteI support the writer's unique point. It is useful and benefit to your daily life.
ReplyDeleteThat's what one may call great post. Seriously, I like it the way you described it and made it easy to understand.
ReplyDeleteThanks…:)Just desire to say your article is as astounding.
ReplyDeleteThank sharing very nice information about multiple parameters i like this article http://www.technologyexplores.com
ReplyDeleteGreat article. Thanks for your great information, the content is quiet interesting. I will be waiting for your next post.
ReplyDeletehi i am trying to do same thing but i am getting error, please help me out :
ReplyDeleteStep 1: In my .js file below code i have placed:
$('#pre_rev_con .submitBtn').on('click',function(){
$.ajax({
type: "POST",
contentType:"application/json;charset=utf-8",
url: "TestAjax.aspx/PopulateUserRegistration",
data:JSON.stringify({fname: 'value1' ,lname: 'value2' }),
dataType:'json',
success: function (data) //what to do if succedded
{
alert(data.d);
},
error: function (jqXHR, textStatus, errorThrown) //what to do if fails
{
alert('bad, ' + errorThrown + ", " + jqXHR.responseText + ", " + textStatus);
}
});
Step 2: .cs file as code as below:
[System.Web.Services.WebMethod]
[ScriptMethod(UseHttpGet = false)]
public string PopulateUserRegistration(string fname, string lname)
{
return ("my name is " + fname + " " + lname);
}
but i am getting parsing Error, plrease help me out
I certainly agree to some points that you have discussed on this post. I appreciate that you have shared some reliable tips on this review.
ReplyDelete