我想使用AJAX POST調用WebMethod,但瀏覽器不斷打開'驗證對話框'。在使用下面詳述的類似代碼之前,我沒有遇到這個問題。
在我search.aspx文件我有以下幾點:
HTML
<a href="javascript: ExpandChild('div4');" runat="server"> <img alt="Students" id="imgdiv4" src="images/arrow-right-b.png" />
</a>
JS
function ExpandChild(input)
{
//somethings are done here
LoadStudentData();
}
function LoadStudentData()
{
$.ajax({
type: "POST",
url: 'webmethods.aspx/TestCall',
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: 'json',
success: function (data) {
alert("ajax called");
},
error: function (result) {
alert("An unknown error occurred, please try again: " + result.responseText);
}
});
}
在我webmethods.aspx文件我有以下幾點:
[WebMethod()]
public static string TestCall()
{
return "it worked";
}
我知道代碼獲取到LoadStudentData方法,但我不知道爲什麼它然後打開身份驗證對話框。 search.aspx頁面和webmethods.aspx頁面都位於我的項目的根目錄中
我正在使用Visual Studio 2015,並且在本地計算機上運行Chrome和Firefox時會出現此問題。調試代碼時,它永遠不會到達TestCall方法。
任何幫助非常明顯。