這讓我難住 - 我不知道問題出在哪裏!C#/ jQuery webservice調用給出了500錯誤
該調用總是返回500錯誤:
查詢:
$('body').on('click', '.day', function() {
// a suspect day has been clicked
if (confirm('Re-index documents received on this day?')) {
// re-index
var day = $(this).find('.day_number').text();
var year = parseInt($('#hidYear').val());
var month = parseInt($('#hidMonth').val());
$.ajax({
type: "POST",
url: "ajax.asmx/ReIndexDay",
data: JSON.stringify({ Month: month, Year: year, Day: day }),
contentType: "application/xml; charset=utf-8",
dataType: "xml",
success: function (data) {
var calendarHTML = $(data).find(':first').text();
// update hidden fields and calendar
$('#hidYear').val(year);
$('#hidMonth').val(month);
$('#divContent').html(calendarHTML);
},
error: function (msg) {
alert("Failed: " + msg.status + ": " + msg.statusText);
}
});
}
});
C#
[WebMethod(Description = "Re-index the day and return HTML of a calendar table for the month")]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public string ReIndexDay(int Day, int Month, int Year)
{
Diagnostic.ReIndex(Day, Month, Year);
return GetIndexCalendarHTML(Month, Year);
}
我卡住了,因此所有的建議表示讚賞!
[編輯]
我得到這個從瀏覽器 - 不知道這是否是準確的,因爲它可能無法重現同樣的事情:
System.InvalidOperationException:請求格式是無效的:應用程序/ XML;字符集= UTF-8。在System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()在System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
[/編輯]
如果它返回一個HTTP 500,表示你的服務器的某處拋出異常那是未被捕獲的。你能夠調試你的網絡方法嗎? – Tejs 2012-04-25 15:16:32
對不起 - 我應該說我已經嘗試調試服務器代碼,但它似乎並沒有受到打擊。這意味着郵件格式有問題,但這一切對我來說都很合適! – CompanyDroneFromSector7G 2012-04-25 15:17:38
使用Fiddler來查看會發生什麼。另一件事contentType是xml,dataType也是,但是你傳遞了一個JSON .. – 2012-04-25 15:18:21