How to do searching in PHP and AJAX?

Question on the very basics of Ajax with PHP?

  • I have a function in my Javascript that is supposed to send an XMLHttpRequest to my php file, and then the onreadystatechange will fire a function to display the info returned from the php file. However, I get a 404 status every time, like the Javascript can't even see the php file, even though they are in the same directory on my server. What am I doing wrong? Here's the Javascript: function getDetails(bookTitle) { request = createRequest(); if (request == null) { alert("Unable to create request!"); return; } var url = "getDetails.php?bookTitle=" + escape(bookTitle); request.open("GET",url,true); request.onreadystatechange = displayDetails; request.send(null); }

  • Answer:

    Try to use the full URL instead of a relative URL, for instance "http://myserver.com/getDetails.php ..."

Waldo at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

... well, have you tried to write the URL by hand to see what's happen? try. if the result is 404, then getDetails.php does not exist... so which is the exact name of the file on server (unix-GNU/Linux-ecc. based server are "case sensitive" meaning getDetails.php is dfferent by getdetails.php and so on - it depends basically by the hosting filesystem, but servers could force exact case match even on filesystems that normally does not care about lettercase).

A 404 means that the browser cannot find the page. Check that the server can run php files (try using a browser to load up the page) and the right permission is on the file. I would try using the full path instead of a relative one and see if that works (try using the browser first, more easier to diagnose then) HTH

As a general rule, you should never use capital letters in any file name (specially not on a server). The GET parameters are fine to use capital, but try to use lowercase in the URL.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.