用jquery时,浏览器的兼容有关问题,在火狐下是好的,但是在IE上跟360上都不行
用jquery时,浏览器的兼容问题,在火狐下是好的,但是在IE上跟360上都不行
<script type="text/javascript">
function checkFun() {
// alert(1);
$.ajax(
{
type: "post",
url: "Index.aspx/GetResult",
data: '{"name":"' + $("#Textbox1").val().trim() + '"}',
datatype: "json",
contentType: "application/json;charset=UTF-8",
success: function (data) {
if (data.d == "false") {
alert("该用户不存在");
return;
}
}
}
);
}
</script>
------解决方案--------------------
增加error回调看输出什么内容
function checkFun() {
// alert(1);
$.ajax(
{
type: "post",
url: "Index.aspx/GetResult",
data: '{"name":"' + $("#Textbox1").val().trim() + '"}',
datatype: "json",
contentType: "application/json;charset=UTF-8",
error:function(xhr){alert(xhr.responseText)},
success: function (data) {
if (data.d == "false") {
alert("该用户不存在");
return;
}
}
}
);
}
------解决方案--------------------
trim 方法不是每个浏览器都支持的
应写作
如果不是在服务端解析 json,则应写作
<script type="text/javascript">
function checkFun() {
// alert(1);
$.ajax(
{
type: "post",
url: "Index.aspx/GetResult",
data: '{"name":"' + $("#Textbox1").val().trim() + '"}',
datatype: "json",
contentType: "application/json;charset=UTF-8",
success: function (data) {
if (data.d == "false") {
alert("该用户不存在");
return;
}
}
}
);
}
</script>
------解决方案--------------------
增加error回调看输出什么内容
function checkFun() {
// alert(1);
$.ajax(
{
type: "post",
url: "Index.aspx/GetResult",
data: '{"name":"' + $("#Textbox1").val().trim() + '"}',
datatype: "json",
contentType: "application/json;charset=UTF-8",
error:function(xhr){alert(xhr.responseText)},
success: function (data) {
if (data.d == "false") {
alert("该用户不存在");
return;
}
}
}
);
}
------解决方案--------------------
trim 方法不是每个浏览器都支持的
应写作
data: '{"name":"' + $.trim($("#Textbox1").val()) + '"}',
如果不是在服务端解析 json,则应写作
data: {name : $.trim($("#Textbox1").val())},