繁体   English   中英

jQuery AJAX调用页面方法不起作用

[英]JQuery AJAX call to page method not working

我有一个aspx网页,它正在使用webservice。 该页面使用javascript编码。 页面和Web服务之间的通信由ajax完成。 当页面触发ajax函数时,会将url参数分配给网站url(localhost / index.aspx#home)。 因此,aspx无法到达Web服务。 而且,我在任何地方都没有对Url参数做任何事情。

这可能是什么问题? 有什么办法吗?

ajax代码块在这里:

$.ajax({
type: "POST",

url: ServiceParameter + "/GET_USER_I_BY_EMAIL",

data: "{username:'" + username + "'}",

contentType: "application/json; charset=utf-8",

dataType: "json",

success: function (msg) {

if (msg.d.length == 0 || msg.d == null) {
if (typeof callback == 'function') {
callback(null);
}
}
else if (msg.d <= 0) {
if (typeof callback_err == 'function') {
callback_err(msg.d, 'SendPass');
}
}
else {
var _data = eval("(" + msg.d + ")");
if (typeof callback_err == 'function' && _data[0] != null && typeof _data[0].ErrorCode != 'undefined') {
callback_err(_data, 'SendPass');
}
else if (typeof callback == 'function') {
callback(_data);
}
}
},
error: function (msg) {
if (typeof callback_err == 'function') {
callback_err(-1, 'SendPass');
}
}
});
}
catch (err) {
if (typeof callback_err == 'function') {
callback_err(-2, 'SendPass');
}
}
},  

尝试下面的代码:

$.post(ServiceParameter + "/GET_USER_I_BY_EMAIL", { username: "myUsername" }, 
    function(data) {
        alert("Data Loaded: " + data)
    }, "json")
    .fail(function() { 
        alert("error"); 
    });

尝试

$.ajax({
type: "POST",
url: ServiceParameter + "/GET_USER_I_BY_EMAIL",
data: {username:'" + username + "'},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
 var jsonData = JSON.parse(msg);
 if (jsonData.d.length == 0 || jsonData.d == null) {
 if (typeof callback == 'function') {
 callback(null);
 }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM