[英]Jquery Ajax call to url not working in ASP.NET
我在我的aspx頁面中使用了ajax調用,還使用了URL重寫。 Ajax調用在沒有URL重寫規則的情況下命中了webMethod,但在應用重寫規則后它將停止工作。
我的aspx頁面ajax調用是:
$.ajax({
type: "POST",
url: "../cc/page.aspx/SendNewsletter",
data: d,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert('hi');
if (response.d == "1") {
alert("Newsletter has been sent successfully.");
}
else {
alert("Something went wrong.Please try again later.");
}
},
failure: function (response) {
alert(response.d);
}
}).always(function () {
});
我的Web方法是:
[WebMethod]
public static string SendNewsletter(string to, string newsletter, string newslettername)
{
}
我的重寫規則是:
<rule name="Rewrite normal CC request to aspx">
<match url="^cc/(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx" />
</rule>
您的urlrewriterule正在將您原來的url /cc/page.aspx/SendNewsletter
變成/cc/page.aspx/SendNewsletter.aspx
將規則更改為以下內容
<rule name="Rewrite normal CC request to aspx" stopProcessing="true">
<match url="^cc/([^/]*)/(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx/{R:2}" />
</rule>
<rule name="Rewrite normal CC" stopProcessing="true">
<match url="^cc/([^?]*)?(.*)$" />
<action type="Rewrite" url="cc/{R:1}.aspx?{R:2}" />
</rule>
並將您的網址更改為../cc/page/SendNewsletter
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.