If I use $.ajax JQuery and I call WebMethod, I get JSON:
$.ajax({
type: "POST",
dataType: "json",
data: JSON.stringify({ id: idX, id2: idY }),
async: true,
cache: false,
url: "/ws/Courses.asmx/GetCourses",
contentType: "application/json; charset=utf-8",
success: function (data) {
RenderCourses(data.d);
},
});
but JSON has "d" property.
function RenderCourses(data) {
if (data.d.length > 0) {
If I use json = JsonConvert.SerializeObject in C#, hasn't the "d" property.
string script = "var data = " + json + "; RenderCourses(data);";
ClientScript.RegisterClientScriptBlock(this.Page.GetType(), "dataVar", script, true);
And RenderCourses fails.
Any reasons?
data: { id: idX, id2: idY },in$.ajaxJSON.stringifyis the problem?