1

Can't able to figure out, why this jquery function always returns an error instead of success.

So I hope to get some feedback ;-)

Thanks in advance!

Bas

$.ajax({
        type : 'POST',
        dataType: 'json',
        url : '/ajax_push_order_status_request.php',           
        data: dataString,
        success:function (data) {
                $('.success').fadeIn(1000);
                $(".success").append(data);
            },

         error: function (data) {
                alert( "ERROR:  " + data );
                $('.error1').fadeIn(1000);
            }


    });  

My PHP script returns:

{"result":true}
Krish R
  • 22,583
  • 7
  • 50
  • 59
Bas
  • 65
  • 5
  • Post your PHP code here. – Krish R Nov 09 '13 at 10:23
  • if you go in your browser to: http://www.zwembad.eu/ajax_push_order_status_request.php You can see it is returning "result":true but in the ajax call you are getting some type of security not allowed error – w3bMak3r Nov 09 '13 at 10:25
  • @w3bMak3r we could go to the url, but this *really* should be part of the question (I'm betting that url will go away before SO :-) – thebjorn Nov 09 '13 at 10:29

3 Answers3

1

Your ajax call is to a different domain (the site is on zwembad.eu while the ajax call goes to www.zwembad.eu). You'll need to use jsonp instead of json and set the Access-Control-Allow-Origin header correctly, or make sure you make the ajax call on the same domain.

thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • OMG! cannot believe that I have overlooked this, shame ;-) Thanks a lot thebjorn an everyone else! – Bas Nov 09 '13 at 15:39
0

Can you make sure the url is in right path.

 url : 'ajax_push_order_status_request.php',    // use this if it is same dir 
Krish R
  • 22,583
  • 7
  • 50
  • 59
0

It`s a cross domain error. If you run the js code on crome console you can see the error

XMLHttpRequest cannot load http://www.zwembad.eu/ajax_push_order_status_request.php. Origin http://zwembad.eu is not allowed by Access-Control-Allow-Origin.

Mickey
  • 173
  • 2
  • 11