Reputation: 33
So I have a very simple request. I am trying to make a call using jQuery to a php file so that the file's response will be put into a "div". I know there are other posts but for some reason none of them seem to be working for me.
Here is my code:
gettable.php
<?php
echo "<p>Great-Success</p>";
?>
sequencingfile.html
jQuery("#tableHolder").load("/path/to/php-file/gettable.php", function(response, status, xhr) {
alert(response);
alert(status);
alert(xhr);
if (status == "error") {
console.log(msg + xhr.status + " " + xhr.statusText);
}
});
Notes
The contents of the div changes to this:
Great-Success
"; ?>
The html code is run after you click a button
The xhr is "[object Object]"
Eventually I am trying to call the php file to query from a mysql database to create a table(if you know of a better and more efficient way of doing this please let me know), but for now all I want is the echo of the php call to come back and be put into the div as it should.
EDIT
Alright I have set up an apache server and changed the link to http://127.0.0.1/gettable.php
and it still doesn't work. When I type that url into firefox or chrome it works, but not when I run the html file. What am I doing wrong?
Upvotes: 0
Views: 425
Reputation: 5911
It needs to be on a webserver. It doesn't work like HTML where you can just place the file where ever and have it run correctly. Download and install WAMP, then run WAMP and place your code in the WWW directory. (if you are on windows, if not - look into LAMP). It stands for Windows/Linux, Apache, MySQL, and PHP. Apache will be your webserver. There are tons of installation guides online. I am not sure which one will work best for you.
If you have a file called test.php
in that folder... you will just go to localhost/test.php
or 127.0.0.1/test.php
Sorry for the Wamp referral I just saw that you are on linux.
Upvotes: 2