i have a following code which runs fine with Mozilla but give object undefined error when run on IE
here is the code
$(document).ready(function () {
$("#button").click(function () {
$.ajax({
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("Content-type",
"application/json; charset=utf-8");
},
data: "{'customerid':" + "'" + $("#check").val + "'}",
url: "ajaxcall.aspx/checkval",
success: function (data) {
var c = data.d;
alert("success");
$("#result").html("day:" + c.seconds);
}
});
});
});
now i have changed my server side c# code inside checkval function using json serialzation
Mydate md = new Mydate();
md.day = DateTime.Now.Day.ToString();
md.month = DateTime.Now.Month.ToString();
md.year = DateTime.Now.Year.ToString();
md.seconds = DateTime.Now.Second.ToString();
JavaScriptSerializer js = new JavaScriptSerializer();
return js.Serialize(md);
Now code is working in IE but only showing the string as
{"month":"10","year":"2011","day":"13","seconds":"44"} and not working with Mozilaa
in place of c.seconds if i write c only in this code
$("#result").html("day:" + c.seconds);
it works for all browsers but the result is
{"month":"10","year":"2011","day":"13","seconds":"44"}
Still not getting what i need
here is the answer atlast i got it in place of this
var c = data.d;
alert("success");
$("#result").html("day:" + c.seconds);
Write
var mydata = $.parseJSON(data.d);
$("#result").html(mydata.seconds);
this will work in IE and Mozilla both
Perhaps a small typo in
data
:"{'customerid':" + "'" + $("#check").val + "'}"
.Have you tried
$("#check").val()
?