weixin_33682719 2014-04-04 17:17
浏览 22

网址重写和Ajax调用

i have a problem with calling web method ( [WebMethod] ) from ajax when i'm using url rewrite to remove the page extention (.aspx).

my ajax works good with rewrite off as follow:

"mypage.aspx/UpdateOffer"

but when i use rewrite i get "parsererror" message from ajax

so i tried this :

"mypage/UpdateOffer"

but then i get error "undefind"

i tried this also ( as suggested by others): PageMethods.set_path(PageMethods.get_path() + '.aspx');

then : "mypage.aspx/UpdateOffer" failed.

also tried : "mypage/UpdateOffer"

failed.

so, how can it be done without errors ?

ty

Edit: my ajax :

PageMethods.set_path(PageMethods.get_path() + '.aspx');
$.ajax({
    url: "myPage.aspx/UpdateOffer",
    type: "POST",
    contentType: "application/json;charset=utf-8",
    dataType: "json",

. . . .

Rewrite config:

  <system.webServer>
    <rewrite>
      <rules>
        <rule name="extensionless" stopProcessing="true">
          <match url="(.*)\.aspx" />
          <action type="Redirect" url="{R:1}" redirectType="Permanent" />
        </rule>
        <rule name="removeextension" enabled="true">
          <match url=".*" negate="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:0}.aspx" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  • 写回答

0条回答 默认 最新

    报告相同问题?