Sina R.
Sina R.

Reputation: 1788

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: *');

Upvotes: 0

Views: 3795

Answers (1)

skyman
skyman

Reputation: 229

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)

Upvotes: 1

Related Questions