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}
3
  • Post your PHP code here. Commented Nov 9, 2013 at 10:23
  • if you go in your browser to: 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 Commented Nov 9, 2013 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 :-) Commented Nov 9, 2013 at 10:29

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

OMG! cannot believe that I have overlooked this, shame ;-) Thanks a lot thebjorn an everyone else!
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 

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.