我能用jquery插件修復我的webservice ajax問題。稱爲jquery.jsonp.js。現在我成功的功能我得到的鉻控制檯窗口在未捕獲
SyntaxError: Unexpected token <
錯誤。我嘗試了各種方法來解決這個問題,但我很茫然
$.jsonp({
type: "POST",
url: "http://localhost:49524/mobile/Android/AndroidWebServices.asmx/CheckLogin",
data: "email="+u+"&password="+p,
crossDomain:true,
success: function (data) {
var s = $(data).find('string').text();;
alert(s);
}
});
,如果有更好的方法來從XML值我將不勝感激任何幫助
<string xmlns="http://wmstec.com/">true</string>
是XML即從WebService
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string CheckLogin(string email, string password)
{
string vid = "xxxx";
//Get the User Information
DB.User cur_user = DB.User.ByEmail(email.Trim());
//if it failed, try by screen name
if (-1 == cur_user.ID) { cur_user = DB.User.ByScreenName(email.ToLower()); }
//Does their password match?
if (cur_user.CheckPassword(password, vid))
{
// companys ToJSON function
return Utility.ToJSON("true");
}
else
{
return Utility.ToJSON(return "false");
}
}
UPDATE
$.ajax({
type : "GET",
url: "http://localhost:49524/mobile/Android/AndroidWebServices.asmx/CheckLogin",
crossDomain:true,
data: "email="+u+"&password="+p,//({ email: u, password: p}),
dataType :"jsonp",
contentType: "application/json; charset=utf-8",
success : function(data){
alert(data);}
});
返回的文件
返回同樣的事情..所以它不一定是JSONP插件,是一個問題..它顯然是一個用戶的問題笑..
所以,你要求JSONP,但返回XML?這聽起來像你的問題。 – 2013-02-26 16:05:52
最有可能您的web服務正在返回XML而不是JSONP。如果你想使用JSONP,你的web服務必須返回JSONP。 JSONP是JSON封裝在回調()中,以便它可以作爲外部腳本執行。 JSON是一種類似於XML的數據格式,但它的語法非常不同,並且非常模仿javascript對象文本的語法。 – 2013-02-26 16:06:05
@KevinB:JSONP不*具有*作爲JavaScript對象(實際上不是JSON)。它通常是,但只要它包含在函數調用中,它可以是任何東西。 – 2013-02-26 16:06:47