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
 php code ...
  ?>"

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

            var formData = new FormData(document.getElementById("signUpForm"));
            $.ajax({
                url: "./cgi-script/signUp.php",
                type: "POST",
                xhr: function giveXmlHTTP(){
                    myXhr = $.ajaxSettings.xhr();
                    if(myXhr.upload){
                        myXhr.upload.addEventListener('progress',progressHandler, false);
                    }
                    return myXhr;
                },
                success: function(data,statusText,jqXHR){
                    alert(jqXHR.responseText);
                },
                data:formData,
                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.

...

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