Jquery Ajax url path Issue

ajax, html, javascript, jquery, php

Solution

If the files you're trying to contact are in the root you can use `/[file].php` so that no matter which page you're on the path will be correct. It sounds like you have a relative path issue. Do you get any errors in the console?

Problem

I am trying to design a message system for my website, but i can't get my ajax running. So I make a simpler version of the interaction between the files. Here is my file both test.php and load.php is under the root folder ( public_html). i have the ajax function in test.php. load.php is just simply echoing "wow". ``` $("#test").click(function(){ alert("Clicked."); $.ajax({ url:"/load.php", type:"POST", beforeSend: function(){ alert("testing"); }, success:function(result){ $("#result").html(result); alert(" sss "+result); } }).error(function(){alert("wrong");}); }); ``` Now It works perfectly. ...........how to set relative path ................... Here is the more complicated design 3 files, all in different folder : - messages.php (under root) - showing all the messages - control.php (root/panels) - a panel will be included in messages.php - load.php (root/functions) - control.php will use ajax to call it then display result in control.php so when user load in messages.php, it will load control.php then run the ajax call control.php. I am so confused about how to set up these paths for ajax ( including control.php in messages.php works fine) Thanks

Original source