Trying to figure out how to convert how to covert 5 variables I have in JavaScript (strings) to a JSON for sending along to my ajax function
here is my ajax function, sill relatively new to this but I believe this should work .. but I need to convert all my strings to a JSON – don’t I?
I believe there are alternative ways of sending data without json, but this is the recommended way isn’t it?
$.ajax({
type: "POST",
url: "MyService.aspx/SendEmail",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg.d);
},
error: function() {
alert('error');
}
});
I believe that at the service end I need to extract the JSON – I am using asp.net
Any ideas?
I suggest you to include in your project JSON2.js, that you can find at this link, and to use the JSON.stringify() function:
if your web service return json data you can parse the result with the library:
It can assure you that your input data will be sanitized from every illegal character.