duandou2763 2016-08-24 09:23
浏览 780

XMLHttpRequest无法加载预检的文件响应无效(重定向)

I recently transferred a website (from the same host, just a couple of folders down) and now my ajax script stopped working.

I get the following error for each script that needs to be loaded:

XMLHttpRequest cannot load http://www.website.nl/includes/loadmore.php. Response for preflight is invalid (redirect)

What could be causing this? This is my ajax script:

(function(){
/*
Meer websites laden
*/
var limit = 3;
var offset = 0;
var i =0;
$('#loadmore').click(function() {
    limit = 3;
    limit = 4;
    if(i == 0) {
        offset += 3;
    } else {
        offset += 4;
    }
    i++;

    ajax();

});

var posts = document.getElementById('loadnews');

function ajax() {
    $.ajax({
    url: 'includes/loadmore.php',
    type: "POST",
    data: {limit: limit, offset: offset},
    success: function(data){
        var newWrapper = document.createElement('div')
        //add class to newWrapper or whatever
        newWrapper.innerHTML=data;
        loadnews.appendChild(newWrapper);
    },
    error: function(jqXHR, exception) {
              if (jqXHR.status === 0) {
                   alert('Not connect.
 Verify Network.');
               } else if (jqXHR.status == 404) {
                   alert('Requested page not found. [404]');
               } else if (jqXHR.status == 500) {
                   alert('Internal Server Error [500].');
               } else if (exception === 'parsererror') {
                   alert('Requested JSON parse failed.');
               } else if (exception === 'timeout') {
                   alert('Time out error.');
               } else if (exception === 'abort') {
                   alert('Ajax request aborted.');
               } else {
                   alert('Uncaught Error.
' + jqXHR.responseText);
               }
           }
    }); 
}

ajax();
}());

I read something on changing the headers that are sent and allowing cross access, but I already do that in my htaccess file. It also doesn't really make sense to me since the files are still on the same host, just a different folder.

Like so:

#Cross site access toestaan
Header set Access-Control-Allow-Origin "*" 
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" 
  • 写回答

1条回答 默认 最新

  • dongzhou1901 2017-09-13 17:55
    关注

    looks like csrf issue so you are getting

    XMLHttpRequest cannot load http://www.website.nl/includes/loadmore.php. Response for preflight is invalid (redirect)
    

    mean you are at http://www.website.nl

    try to send ajax request from http://website.nl

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示