简体   繁体   English

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

[英]JQuery AJAX call to page method not working

I have an aspx webpage and it is using webservice. 我有一个aspx网页,它正在使用webservice。 The page is coded with javascript. 该页面使用javascript编码。 The communication between page and webservice is done by ajax. 页面和Web服务之间的通信由ajax完成。 When the page fires ajax function, the url parameter is assigned to website url (localhost/index.aspx#home). 当页面触发ajax函数时,会将url参数分配给网站url(localhost / index.aspx#home)。 therefore, the aspx cannot reach the webservice. 因此,aspx无法到达Web服务。 Moreover, I did not do anything with Url parameter anywhere. 而且,我在任何地方都没有对Url参数做任何事情。

What can be the problem here? 这可能是什么问题? Any solution? 有什么办法吗?

the ajax code block is here: 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');
}
}
},  

Try with the next code: 尝试下面的代码:

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

try 尝试

$.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