Jump to content

Recommended Posts

Hello. I am new at AJAX, today, I made a small script, that will post a data and return that data.

It works very well in my Localhost:

PIKEYj0.png

but after I had uploaded to my hosting, It didn't work anymore.

dieisVb.png

 

I don't understand what happened.

here is my code:

file ajax_post :

 

 



<!DOCTYPE html>
<html>
<head>
<title>The 2nd ajax</title>
<meta charset="UTF-8">
<script>
function loadXML(){
var httpXML;
if (window.XMLHttpRequest) httpXML= new XMLHttpRequest();
else httpXML=new ActiveXObject("Microsoft.XMLHTTP");
httpXML.onreadystatechange=function(){
/* readyState: 0: request not initialized
1: server connection established
2: request received
3: processing request
4: request fished and response is readyState
status: 200: "ok";
404: page not found */

if (httpXML.readyState==4 && httpXML.status==200){
document.getElementById('myDiv').innerHTML= httpXML.responseText;
}

}
httpXML.open("POST","test.php",true);
httpXML.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpXML.send("input="+document.getElementById('form1').value);



}
</script>
<body>

<input type="text" value ="Type something" name ="input" id="form1"/>

<button type="submit" onclick ="loadXML()"> Click here</button>



<div id="myDiv"> The information appears here. </div>
</body>
</head>


 

file test.php: 



<?php
echo "you have inputted:".$_POST['input'];
?>


 

 

Please help me to resolve this!

Link to comment
https://forums.phpfreaks.com/topic/294832-ajax-cant-post-a-data-to-php-file/
Share on other sites

  • 1 month later...

If it was working, and no longer is then it's probably not the code, unless it was changed as well.  First place to look is on the hosting servers file system.  Check that the php file is in the same folder as the file that is running the xhtml request.  Then check that the permissions are right on file and folder.  I assume your hosting provider provides php hosting...

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.