简体   繁体   中英

Cross-domain Ajax request error

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?

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


Answer :

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

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

Read this first: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

You should add header:

Access-Control-Allow-Origin: *

to server response ( http://www.mint-co.ir/fix_dl/validate_captcha.php )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM