dounao1875 2018-08-18 00:39
浏览 1225

如何绕过跨源请求被阻止的CORS请求在此脚本中没有成功?

On my local machine all Ajax requests work just fine and the app works perfectly. It is a different story on the host machine. When trying to execute below Ajax script I get :

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://googleads.g.doubleclick.net/pagead/id. (Reason: CORS request did not succeed).

I spent all day trying to fix this error to no avail. I even added this in the head of every page

  <?php ob_start(); 
       header('Content-Type: text/html; charset=utf-8');
       header("Access-Control-Allow-Origin: *");
       ?>

I read about JSONP and I'm wondering how to implement this solution?

This is the short version of the Ajax

       $( ".submit-signup-form" ).click(function(e) {
       e.preventDefault();

       if(formvalues!==''){
       $("#sign-up-form-2").submit(

       $.ajax({
           type: "POST",
           url: 'queries/register.php',
           data: formvalues,
           success: function(customerarr){ //callback}
      })
      })

     });
}

When debugging the app in the console I tried console.log(formvalues) and everything printed out okay. The form does get ALL the variables so I'm not understanding how to make the script work on live host.

  • 写回答

1条回答 默认 最新

  • doushenxu7294 2018-08-18 06:00
    关注

    You can use this in ajax request...

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

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料