User1316246260 posted
I have a subroutinr:
[WebMethod]
public static string gvAjax()
{
List<Table1> gvlist = new List<Table1>();
...
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var json1 = serializer.Serialize(gvlist).ToString();
return json1;
}
I get a string from the WebMethod of the form "[{"Id":1,"col1":"11","col2":"22","col3":"33"},"{"Id":2,"col1":"44","col2":"55","col3":"66"},"{"Id":3,"col1":"77","col2":"88","col3":"99"}]"
The alert gives a message of "undefined".
How do I get Ajax to read my json string?
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#<%= Button2.ClientID %>").click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/Default.aspx/gvAjax",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({}),
async: true,
cache: false,
success: function (data) {
alert(data.d);
},
error: function (x, e) {
alert("Error: " + x.responseText);
}
});
});
});
</script>