星空网 > 软件开发 > Java

jquery ajax跨域访问webservice配置

1.webservice方法

 [System.Web.Script.Services.ScriptService]  public class TestService : System.Web.Services.WebService  {        [WebMethod]    public string Test(string inputStr)    {      ////HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");      return "Hello :"+inputStr;    }  }

2.webservice网站web.config配置

 <?
<!--
  有关如何配置 ASP.NET 应用程序的详细信息,请访问
  jquery ajax跨域访问webservice配置http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.0" />
      <customErrors mode="Off"/>
      <webServices>
        <protocols>
          <add name="HttpSoap"/>
          <add name="HttpPost"/>
          <add name="HttpGet"/>
          <add name="Documentation"/>
        </protocols>
      </webServices>
    </system.web>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
        <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
        <add name="Access-Control-Allow-Origin" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>

</configuration>
jquery ajax跨域访问webservice配置
图中框出的2块经测试 缺一不可
 

3.jquery ajax调用

function doClick1() {
      jQuery.support.cors = true; //IE10以下
    $.ajax({      type: "post",      url: "http://xx.com/TestService.asmx/Test",      dataType: ',      data: { inputStr: 'everyone' },      success: function (data) {        alert(data); //function ('error:' + errorThrown);      }    });  }

 


 From:  http://www.cnblogs.com/xuejianxiyang/p/5369346.html



原标题:jquery ajax跨域访问webservice配置

关键词:jquery

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

西法市场:https://www.goluckyvip.com/tag/43744.html
西瓜出海:https://www.goluckyvip.com/tag/43745.html
西瓜跨境:https://www.goluckyvip.com/tag/43746.html
西红柿:https://www.goluckyvip.com/tag/43747.html
西集网:https://www.goluckyvip.com/tag/43748.html
西联汇款 Western Union :https://www.goluckyvip.com/tag/43749.html
湘西游轮六 湘江游轮夜游:https://www.vstour.cn/a/411226.html
携程旅游网折扣优惠最新攻略(携程旅游网更佳折扣优惠):https://www.vstour.cn/a/411227.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流