简体   繁体   中英

JQuery AJAX call to page method not working

I have an aspx webpage and it is using webservice. The page is coded with javascript. The communication between page and webservice is done by ajax. When the page fires ajax function, the url parameter is assigned to website url (localhost/index.aspx#home). therefore, the aspx cannot reach the webservice. Moreover, I did not do anything with Url parameter anywhere.

What can be the problem here? Any solution?

the ajax code block is here:

$.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);
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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