March 9, 2013

why is jqXHR.responseText returning my PHP file and not executing the script?

Question by Mr.Student

I’m trying to simply execute an ajax request to my server. The request passes my form data to signUp.php where the information is then process. Then php will echo back a responseText to my jqXHR object and I print the alert. The problem is that my php file is being executed, rather the jqXHR.responseText is instead returning the my php file itself as if it were a text file. A sample php responseTest would look like …

 php code ...

Instead I want the responseText to return my echoes. The code is written bellow.

            var formData = new FormData(document.getElementById("signUpForm"));
                url: "./cgi-script/signUp.php",
                type: "POST",
                xhr: function giveXmlHTTP(){
                    myXhr = $.ajaxSettings.xhr();
                        myXhr.upload.addEventListener('progress',progressHandler, false);
                    return myXhr;
                success: function(data,statusText,jqXHR){
                cache: false,
                contentType: false,
                processData: false


Answer by Starx

These generally happens when PHP does not gets parsed. So make sure you are running on the SERVER which is capable and configured to run PHP and are not double clicking the HTML page.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!