[英]Ajax Auto complete Css works fine in iis and the server but not in local machine
[英].Ajax method works on local machine, but not on server
我有一個.Ajax方法,該方法在后面的頁面上調用一個方法(執行一些邏輯,然后調用WCF服務,然后返回一個對象),如下所示:
$.ajax({
type: 'POST',
url: 'MyPage.aspx/TestMethod',
dataType: "json",
contentType: "application/json",
data: "{'Id': '" + Id + "'}",
success: function (data) {
$("#randomElement").html(data.d.Foo);
},
error: function ((xhr, textStatus, error){
alert(xhr.statusText);
alert(textStatus);
alert(error);
});
和后面的頁面:
[System.Web.Services.WebMethod]
public static MyObject TestMethod(string Id)
{
//Logic removed for readability!
return MyService.GetStuff(Id);
}
這在我的本地計算機上可以很好地工作,但是當我部署到服務器時卻無法工作。
我確定沒有調用方法后面的頁面(即,錯誤在於調用TestMethod()而不是調用服務的TestMethod())。
我還在.ajax方法之前放置了一個警報,以向我顯示我所在頁面的路徑,以防萬一它對實時服務器上的uri做一些有趣的事情,並以“ /MyPage.aspx”形式返回我希望。
我還將“ url:”更改為完整的uri,以查看是否有幫助,但沒有幫助。
在關閉自定義錯誤的情況下運行提琴手后,出現以下錯誤:
在System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo方法,Object target,Object []參數,SignatureStruct&sig,MethodAttributes methodAttributes,RuntimeType typeOwner)\\ r \\ n處的{“ Message”:“線程正在中止。”,“ StackTrace”:“ System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo方法,對象目標,Object []參數,簽名sig,MethodAttributes methodAttributes,RuntimeType typeOwner)在System.Reflection.RuntimeMethodInfo.Invoke(對象obj,BindingFlags invokeAttr,活頁夾活頁夾,對象[ ]參數,CultureInfo文化,System.Reflection.RuntimeMethodInfo.Invoke(對象obj,BindingFlags invokeAttr,活頁夾活頁夾,Object []參數,CultureInfo文化)在System.Web.Script處的布爾型skipVisibilityChecks)\\ r \\ n。 Services.WebServiceMethodData.CallMethod(對象目標,IDictionary
2 parameters)\\r\\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2個參數)\\ r \\ n在System.Web.Script處。 Services.RestHandler.InvokeMethod(HttpContext上下文,WebServiceMethodData methodData,IDictionary`2 rawParams)\\ r \\ n位於System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext上下文,WebServiceMethodData methodData)“,” ExceptionType“:” System.Threading .ThreadAbortException“}
您的JSON無效; 您需要使用雙引號:
data: '{"Id": "' + Id + '"}',
在我看來,它沒有在您的方法中發布正確的參數。
我從未像以前一樣在.ajax方法中使用data選項。 我用:
data: {Id: myId},
其中myId是保存要傳遞的Id值的變量-不帶引號。
\\ r \\ n通常是與編碼字符串有關的東西,在這里這不應該與之相關,並且似乎您正在傳遞字符串數據:“ {'Id':'” + Id +“'}”代替一個對象。
您的服務器是否有“ json”? 例如,godaddy不提供
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.