I try to use ajax call in my aspx page. Here is my script:
<head runat="server">
<title></title>
<script type="text/javascript" src="jquery/ui/jquery-ui-1.8.23.custom.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "WebForm1.aspx/List",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert('asd');
}
});
});
</script>
</head>
Here is my server side code:
[WebMethod]
public static string[] List()
{
...
}
I put a break point List’s first row but nothing happen. Do you have any suggestion, where I make a mistake?
The parameter you’re specifying is json; but where’s the json data??
data: '{}',is an object. Also, I’d check the url parameter. Presumably, you’d need to write your call like this:And then on the server side, you should therefore specify that you’re receiving a string, since that’s the format of json data. I would also recommend changing the name of the WebMethod because
Listcan be confusing. And finally, you’re returning json, therefore you’re returning a string and not an array. Server method like this: