跨域Ajax请求错误 [英] Cross-domain Ajax request error

查看:121
本文介绍了跨域Ajax请求错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能发送这个ajax请求?

Why I can't send this ajax request?

        $.ajax({
          type: "POST",
          url: 'http://www.mint-co.ir/fix_dl/validate_captcha.php',
          data: window.$form.serialize(),
          crossDomain:true,
          cache:false,
          dataType:'text',
          success:function(res){
            alert(res);
          },
          error:function(a,b,c){
            alert(b);
            alert(c);
          }
        });

它总是失败并触发错误功能. +仅在错误函数中出现字符串错误"时,不会发出任何警报.我的请求是跨域的.我该怎么办?

It always fails and fires error function. + nothing will be alerted just a string 'error' in error function. my request is cross-domain. How can I get what is the error?

这是其中的一个jsfiddle: http://jsfiddle.net/zq34Z/

Here is a jsfiddle of it:http://jsfiddle.net/zq34Z/

答案:

现在我明白了,我应该在请求的文件中添加标题(响应)

Now I got it I should add header in the requested file (response)

header('Access-Control-Allow-Origin: *');

推荐答案

请先阅读以下内容: https ://en.wikipedia.org/wiki/Cross-origin_resource_sharing

您应该添加标题:

Access-Control-Allow-Origin: *

对服务器的响应( http://www.mint-co.ir/fix_dl /validate_captcha.php )

这篇关于跨域Ajax请求错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆