I a trying to AJAX a variable from a javascript/HTML file and recieve the variab
ID: 3787150 • Letter: I
Question
I a trying to AJAX a variable from a javascript/HTML file and recieve the variable in a php file. It works on my localhost server, but after deploying my site the AJAX doesn't work.
Her is the javascript:
Here is the PHP Script:
This is the error I am getting when the site is deployed:
Error:
function showTweetsO 1 Create our XMLHttpRequest object var hr new XMLHttpRequesto; Create some variables we need to send to our PHP file var url "/home2/passeng7/public html/parsefile .php"; var selopt3 document getElementByIdC"choice2") value var vars selopt3 console. log(vars); r Open url, true); Set content type header information for sending url encoded variables in the request hr.setRequestHeaderC"Content-type", "application/x-www-form-urlencoded"); Access the onreadystatechange event for the XMLHttpRequest object O hr. onreadystatechange function ifChr.readyState 4 && hr. status 200) 1 var return data hr. responseText document innerHTML return data Send the data to PHP now. and wait for response to update the status div Actually execute the request hr. openC"GET", "parsefile.php?username +vars, true); hr Sen document.getElementByIdC"status") innerHTML processingExplanation / Answer
500 is server error.
The settings in the server are not the same as in your local, this is why you are getting error. Try the replicate your local environment in server.
1. Check whether the file path is right, try adding './' before the file name.
2. Check your php file whether there is any code that is writing to DB with insufficient rights or reading another file which is unavailable.
3. Check your rights in the server.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.