Search code examples
phpajaxno-response

PHP AJAX getting no response


I'm using PHP and AJAX to make a post in a page. Below is the javascript code of the page.

function Post(posted_by, posted_to)
    {
        document.getElementById('post_textarea').disabled='disabled';
        document.getElementById('post_button').style.display='none';
        document.getElementById('loader').style.display='inline';

        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttpPost=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttpPost=new ActiveXObject("Microsoft.XMLHTTP");
        }

        var post=document.getElementById("post_textarea").value;
        var params="type=post&posted_by=" + posted_by + "&posted_to=" + posted_to + "&post=" + post //Parameters for post method..

        xmlhttpPost.open("POST","test.php",true);

        //Send headers; data sent as if it has been posted from form
        xmlhttpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttpPost.setRequestHeader("Content-length", params.length);
        xmlhttpPost.setRequestHeader("Connection", "close");

        xmlhttpPost.onreadystatechange=function()
        {   
            //I can reach here...

            if (xmlhttpPost.readyState==4 && xmlhttpPost.status==200)
            {
                //BUT I CAN'T REACH HERE.. GETTING NO RESPONSE
                document.getElementById('posts').innerHTML = xmlhttpPost.responseText + document.getElementById('posts').innerHTML;
                document.getElementById("post_textarea").value=""; //Clear textbox
                hidePostBox();
            }
        }

        xmlhttpPost.send(params); //Send POST DATA to the server.. 
    }

In the PHP file, I've ECHOed a line of text to test if it works.

But I'm no getting that line of text as a repsonse. No response at all.

I was using this same javascript code in another website and it was working. And the same code here ain't working.

What might the glitch??


Solution

  • Okay. I never used ERROR CONSOLE. And I used it today for the first time. And found the problem was it was not getting the PHP file as I had use HTACCESS URL Rewriting and it messed with it