[英]URL for ajax not working properly in asp.net
我最近在我的Web應用程序中添加了一些URL重寫,並且不得不在所有腳本圖像等引用中添加Page.Resolve URL。 現在在這些腳本中,我有一些ajax調用,現在不再能找到我的web服務。 請求網址錯誤,我看到了該錯誤消息。 無論如何,我可以使用我的Web服務嗎? 謝謝你的幫助。
我原來的那件事現在不起作用
$.ajax({
type: "POST",
url: "../MainService.asmx/UpdateInformation",
contentType: "application/json; charset=utf-8",
data: parameter,
dataType: "json",
使用此代替:
url: '<%=ResolveClientUrl("~/MainService.asmx/UpdateInformation")%>',
這將獨立於用戶所在的路徑來解析正確的URL。 注意~
。 這意味着該路徑將從網站的根目錄開始。
嘗試將url
參數替換為:
url: "/MainService.asmx/UpdateInformation",
要么
url: "MainService.asmx/UpdateInformation",
總是可以添加這樣的東西
<script type="text/javascript">
<% var siteroot = Url.Content("~/") %>
$.ajax({
type: "POST",
url: siteroot + "MainService.asmx/UpdateInformation",
contentType: "application/json; charset=utf-8",
data: parameter,
dataType: "json",
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.