-1

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?

3 Answers 3

4

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/ ).

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

1 Comment

yeah that's it :P sorry for my very useless question
1

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});

1 Comment

1- Yes the page works correctly with the browser 2- Doesn't really do anything 3- Changed it, same result
0

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.

1 Comment

yeah I did try access through the browser and the script works correctly

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.