tags:

views:

43

answers:

3

I have a small problem, I want to load data from a PHP file and put them on a DIV.

Here's the Jquery code

 // Store the username in a variable
 var jq_username = $("#txt_checkuser").val();
 // Prepare the link variable
 var link = 'user.php?action=check&username=' + jq_username;
$('div #checkuser_hint').load(link);

So it works! but instead of loading the result (compiled PHP) it loads the PHP code.

If I write the long URL "http://localhost/project..." it doesn't load anything!

Any idea how to do that?

+4  A: 

I think you might be accessing your javascript file as a file on your local filesystem, a request to the same directory would go through the filesystem and not through your webserver, processing the PHP into the desired output. This also explains why http://localhost/project for the AJAX call doesn't work: Javascript might be enforcing the same-origin policy on you.

Verify that you're actually accessing this javascript file through http://localhost/ (as opposed to something like file://C:/My PHP Files/ ).

MathieuK
yeah that's it :Psorry for my very useless question
Omar Abid
A: 

Are you able to access the script manually on your own? (try accessing it via your browser: htp://localhost/...) It may be the case that you're missing your opening <?php and/or closing ?> in the script-file itself.

Jonathan Sampson
yeah I did try access through the browser and the script works correctly
Omar Abid
+1  A: 

Does the page return anything when you use your browser?

Are you sure it should not be 'div#checkuser_hint' instead of 'div #checkuser_hint' ?

And this looks like the correct way according to the documentation.

var link = 'user.php';
$('div#checkuser_hint').load(link, {'action':'check', 'username':jq_username});
OIS
1- Yes the page works correctly with the browser2- Doesn't really do anything3- Changed it, same result
Omar Abid