我在做一個AJAX調用一個WebMethod,我得到錯誤「意外令牌「」我不知道爲什麼我得到這個..任何想法?意外標記> jQuery的AJAX
function addToQueue(me) {
if (validateTimeFrame()) {
$.ajax({
method: "POST",
url: "GenerateReportModal.aspx/AddToPrintQueue?id=" + $('#patientNum').val(),
data: {buttonID: me.id},
dataType: "json",
success: function (data, textStatus, jqXHR) {
alert(data);
$('#GenerateReportModal').dialog('close');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown + ' ' + textStatus);
console.log(jqXHR);
$('#GenerateReportModal').dialog('close');
}
});
}
}
< ------------------------------------------ ----->
[WebMethod]
public string AddToPrintQueue(string buttonID)
{
try
{
var deIdentify = 0;
var adminUserNum = Int32.Parse(Session["AdminUserNum"].ToString());
if ((Session["AdminUserNum"].ToString() == "6460" || Session["AdminUserNum"].ToString() == "6537" || Session["AdminUserNum"].ToString() == "7885") && (Session["ClinicalDataAdmin"].ToString() == "1" || Session["AccountAdmin"].ToString() == "1" || Session["SystemAdmin"].ToString() == "1"))
deIdentify = (cbDeIdentify.Checked == true) ? 1 : 0;
else
deIdentify = 0;
switch (buttonID)
{
case "FollowUpAddtoQueue":
FollowUpAddToQueueClass(deIdentify);
break;
case "WearTimeAddToQueue":
WearTimeAddToQueueClass(deIdentify);
break;
case "TrendsAddToQueue":
TrendsAddToQueueClass(deIdentify);
break;
case "EndOfUseAddToQueue":
EndofUseAddToQueueClass(deIdentify);
break;
}
}
catch
{
return "There was an issue, we appologize for the inconvenience";
}
return "Added to print queue";
}
< ------------------------------------ ---------------->
<asp:Button runat="server" OnClientClick="return addToQueue(this); return false;" CssClass="button" ID="EndOfUseAddToQueue" Width="150" Text="<%$ Resources:PatientDetail, btnModAddtoQueue %>" />
您是否獲得'data'成'警報(數據)'? –
這是因爲瀏覽器並不期望從你的WebMethod返回的結束。你的迴應有些語法錯誤。 –
@Dhaval - 它不會成功,所以我不確定。它返回錯誤函數。 – dave