aamunye
aamunye

Reputation: 33

Where should I host php file for ajax call?

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

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

Answers (1)

gloomy.penguin
gloomy.penguin

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

Related Questions