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? 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. 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? 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. 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 I don't appreciate the sarcasm, it was a genuine question, if you don't want to help then thats fine. 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. 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. Link to comment https://forums.phpfreaks.com/topic/279820-ajax-absolute-path-issue/#findComment-1439352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.