1internet Posted July 3, 2013 Share Posted July 3, 2013 I am going crazy with my ajax calls. I have finally discovered the issue, but tried numerous ways to fix it with no avail. So essentially I have an ajax call from different levels in the site, there could be from 1 to 4 different directories in the url of the site, which is what causes the issues. function add_cart(pid,quantity) { $.ajax({ type : 'POST', url : '../../ajax/add-cart.php', data : 'pid='+pid+'&quantity='+quantity, success : function() {} }); } I have tried changing the path to http://www.mydomain.com/ajax/add-cart.php, /ajax/add-cart.php, document.location.origin+"/ajax/add-cart.php", "//www.mydomain.com/ajax/add-cart.php" But nothing is working. I am sure I am not the first person to run into this issue, so what is the answer? Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/ Share on other sites More sharing options...
trq Posted July 3, 2013 Share Posted July 3, 2013 Note that the option is called url, pass it a url. Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439196 Share on other sites More sharing options...
1internet Posted July 3, 2013 Author Share Posted July 3, 2013 Can you elaborate? Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439197 Share on other sites More sharing options...
trq Posted July 3, 2013 Share Posted July 3, 2013 Your not sure what a url is? http://en.wikipedia.org/wiki/Url So, passing [nobbc]http://foo.com/script.php[/nobcc] should work from any location. If your url doesn't work, there is some other issue. Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439201 Share on other sites More sharing options...
1internet Posted July 3, 2013 Author Share Posted July 3, 2013 (edited) I don't appreciate the sarcasm, it was a genuine question, if you don't want to help then thats fine. Edited July 3, 2013 by 1internet Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439204 Share on other sites More sharing options...
trq Posted July 3, 2013 Share Posted July 3, 2013 Sorry, I'm seriously not trying to be sarcastic. Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439205 Share on other sites More sharing options...
1internet Posted July 3, 2013 Author Share Posted July 3, 2013 Ok, sorry, that was just how I inferred it. On a lighter note, it works now. So thanks. Quote Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.