顯示具有 AJAX 標籤的文章。 顯示所有文章
顯示具有 AJAX 標籤的文章。 顯示所有文章

2012年9月27日 星期四

jQuery ajax post 在IIS中無法存取 WebService (*.asmx)



有某段程式碼如下,在本機測試時沒問題,一放到IIS上就失敗

$.ajax({
type: "POST",
url: "/Services/CommonService.asmx/QueryNation",
data: '',
async: false,
success: function (result) {
var msg = $(result.lastChild).text();
alert(msg);
}
});


有兩種方式解決:

1. 在IIS上設定虛擬目錄,指向存放webservice的資料夾

2. 在web.config上設定webService區段,如下:
<!-- 設定允許Service存取 -->
<configuration>
 <system.web>
    <webServices>
      <protocols>
        <add name="HttpPost" />
      </protocols>
    </webServices>
 </system.web>
</configuration>

2011年9月22日 星期四

當網站部屬到IIS後 使用jQuery ajax呼叫webService(.asmx)失敗

在本機開發的時候可以正常呼叫,一但部署到IIS上面就發成錯誤
檢查error status為404錯誤

解決方式:
在web.config加入


<configuration>
  <system.web>
    <webServices>
       <protocols>
          <add name="HttpPost" />
       </protocols>
    </webServices>
  </system.web>
</configuration>

2011年4月14日 星期四

使用chrome或firefox,無法在ashx中取得session

問題1:
當context.Session = null,是因為少繼承了IRequiresSessionState介面
於是需改成

using System.Web.SessionState;

public class Handler : IHttpHandler, IRequiresSessionState
{ ... }

問題2:
雖然context.Session != null了,但是Session.Count = 0,無法取得由aspx所設定的session值
於是需在 web.config 中加入

<configuration>
<system.web>
<sessionState cookieless="UseUri" />
</system.web>
</configuration>

OK! 可順利取到值了

2011年3月2日 星期三

找不到Sys命名空間

只要在aspx檔案中加入

<asp:ScriptManager runat="server" id="ScriptManager1" />

就會出現了... orz