2013-07-26 38 views
0

我有一個HTM頁面和一個service.aspx和service.aspx.cs文件在我當前的應用程序。我正在使用.Net 4.0。在service.aspx.cs頁面我有testmethod如下。Jquery ajax沒有打到服務器

[WebMethod] 
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Xml)] 
public static string test() 
{ 
    return "AA"; 
} 

在我的HTML頁面

$.ajax({ 
    type: "GET", 
    cache: false, 
    url: "NextGenFormService.aspx/test", 
    dataType: "xml", 
    contentType: "text/html", 
    success: AjaxSucceeded, 
    error: AjaxFailed 
}); //end of $.ajax; 

如果我繼續在我的服務器一個破發點但不打。 AjaxSucceeded被調用200 OK並且responseText爲空。

同樣適用於contenttype:application/json,數據類型:json。

我想從服務器或測試方法發送什麼,只不過是HTML和JavaScript。

+0

已經在瀏覽器中檢查您的網址是它的工作? –

+0

嘗試安裝Fiddler2來監控您的請求。它對這個請求說了什麼? – Tdelang

+0

小提琴手的迴應即將消失。 – Shiras

回答

0

使用默認contentType,因爲您不發送任何數據,請更改爲html數據類型。

有時asp.net不喜歡所丟失的數據屬性,甚至連空的,像這樣:

$.ajax({ 
    data:{}, 
    type: "GET", 
    cache: false, 
    url: "NextGenFormService.aspx/test", 
    dataType: "html", 
    contentType: "application/x-www-form-urlencoded;", 
    success: AjaxSucceeded, 
    error: AjaxFailed 
}); 
相關問題