jQuery的AJAX方法返回null值 [英] jquery ajax method returns null value
本文介绍了jQuery的AJAX方法返回null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个AJAX功能是这样的:
$阿贾克斯({
键入:POST,
网址:'AjaxControls.aspx / CreateUserLevel',
数据:{LevelNameAddLevel:$('#LevelNameAddLevel)VAL()},
数据类型:JSON
成功:函数(响应)
{
的console.log(响应);
如果(响应==真)
{
$(#ErrorDivAddLevel)HTML('级别创建成功!')淡入(慢)。
}
其他
{
$(#SuccessDivAddLevel)HTML('级别创建失败!')淡入(慢)。
}
}
});
问题是,响应中返回一个空值。
该网站的方法是:
<的WebMethod(EnableSession:= FALSE)>
公共共享功能CreateUserLevel()作为字符串
返回True
结束功能
解决方案
首先你要有的contentType其他明智它不知道它的解析,例如的contentType:应用/ JSON,
你应该strigify数据
数据:JSON.stringify({LevelNameAddLevel:$('#LevelNameAddLevel)VAL()})
I have an ajax function like this:
$.ajax({
type: "POST",
url: 'AjaxControls.aspx/CreateUserLevel',
data: { LevelNameAddLevel: $('#LevelNameAddLevel').val() },
dataType: "json",
success: function (response)
{
console.log(response);
if (response == "true")
{
$("#ErrorDivAddLevel").html('Level created successfully!').fadeIn('slow');
}
else
{
$("#SuccessDivAddLevel").html('Level creation failed!').fadeIn('slow');
}
}
});
The issue is that the response returned a null value.
The web method is:
<WebMethod(EnableSession:=False)>
Public Shared Function CreateUserLevel() As String
Return "true"
End Function
解决方案
first you should have contentType other wise it doesnt know what its parsing, for example contentType: "application/json",
and you should strigify your data
data: JSON.stringify({ LevelNameAddLevel: $('#LevelNameAddLevel').val() }),
这篇关于jQuery的AJAX方法返回null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文