响应预检请求未通过访问控制检查:否'Access-Control-Allow-Origin'

时间:2018-09-22 05:04:07

标签: php jquery ajax api login

您好,我正在使用jquery ajax方法获取登录令牌的权限,但收到此消息

  

无法加载https://login.salesforce.com/services/Soap/u/42.0?wsdl:   对预检请求的响应未通过访问控制检查:否   请求中存在“ Access-Control-Allow-Origin”标头   资源。来源'https://www.example.com

$(document).ready(function(){

                //alert('blnk');
      $.ajax({

         headers: {

        "Accept" :'application/json'   //If your header name has spaces or any other char not appropriate
     },
            url: 'https://login.salesforce.com/services/Soap/u/42.0?wsdl',
             contentType: "application/json; charset=utf-8",
    type: 'post',dataType: "post",data:JSON.stringify( {username  :'demo',  password  :'demo'}),
        crossDomain: true, 

        success: function(resuklt){
         console.log(resuklt);  

        }});
     [enter image description here][1]
    });

1 个答案:

答案 0 :(得分:0)

请使用...

dataType: 'jsonp',  //use jsonp data type in order to perform cross domain ajax
  crossDomain: true,

在成功执行功能之前。