• jquery ajax跨域请求webservice


    有种方式可以通过JSONP方式来请求

    这里具体介绍如何通过修改配置文件来实体AJAX跨域请求WEBSERVICE

     WEBSERVICE的类声名

        /// <summary>
        /// MobileService 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        [System.Web.Script.Services.ScriptService]
        public class TestService : System.Web.Services.WebService
        {
        }

    WEBCONFIG的修改

      开启允许POST GET请求

     <add name="HttpGet"/> 
    <add name="HttpPost"/>
    开启允许跨域请求
          <add name="Access-Control-Allow-Methods" value="OPTIONS,POST,GET"/>
          <add name="Access-Control-Allow-Headers" value="x-requested-with,content-type"/>
          <!--Value="*"不限制域名 -->
          <add name="Access-Control-Allow-Origin"  value="http://domain1.com, http://domain2.com" />
     
    <configuration>
        <system.web>
          <compilation debug="true" targetFramework="4.0" />
          <webServices>
            <protocols>
              <add name="HttpGet"/>
              <add name="HttpPost"/>
            </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"/>
          <!--Value="*"不限制域名 -->
          <add name="Access-Control-Allow-Origin"  value="http://domain1.com, http://domain2.com" />
        </customHeaders>
      </httpProtocol>
      <modules>
        <add name="MyHttpModule" type="WebServiceDemo.MyHttpModule"/>
      </modules>
      </system.webServer>
    </configuration>

    AJAX示例代码


    $.ajax({
                    type: "POST",
                    url: "http://10.10.0.1:8888/XXXXX.asmx/XXXXX",
                    dataType: "JSON",
                    contentType: "application/json",
                    data: { Data1: "HELLO", Data2: "WORD" },
                    success: function (msg) {
                        alert(msg);
                    }
                });

  • 相关阅读:
    java_decompile 反编译工具
    python时间函数time
    Stuck in the process of compiling C++ extensions 卡住解决方法 time.sleep(self.wait_seconds)
    在一张图像上截图一部分区域python
    typora beta版(还可以免费下载)
    Truncation trick是什么?
    git clone失败:fatal: unable to access 'https://github.com/NVIDIA/apex/': gnutls_handshake() failed: The TLS connection was nonproperly terminated.
    消融实验ablation study
    将一张图像贴到另一张图像指定区域
    with tf.compat.v1.Session() as sess用法详解
  • 原文地址:https://www.cnblogs.com/enya1999/p/4134027.html
Copyright © 2020-2023  润新知