Reputation: 7854
I would like to have an AJAX call with the following type,
$.ajax({
url:"../..",
data:{
stringvar:$("..").val(),
jsonobj:JSON.stringify({
}),
anotherstringvar:$("..").val()
},
type:"POST",
content-type:"application/json"
success:function(data){
// do something with the data
}
});
How do I achieve this kind of requirement. As you find above, i have to pass normal string values along with the JSON data and i have to bind the same using ASP.NET MVC2 Model binder and JSONValueProviderFactory, which have in place.
Upvotes: 1
Views: 226
Reputation: 2333
You can create a simple JSON object and send it to the server:
var data = JSON.stringify(valuetobestringified);
var json = {
"json": data,
"anotherstringvar": $("..").val(),
"anotherstringvar1": $("..").val()
}
$.post("../..",json,function(){
//response from the server.
});
You can find more information about jQuery here: http://api.jquery.com/jQuery.post/
And you can create a simple JSON object with this online editor: http://jsonlint.com/
Upvotes: 1