Thanks for taking your time to help me out.
The situation:
I'm having some trouble getting some data by AJAX using jQuery on Cloud9 (http://c9.io). All files are in the same directory.
Here are the codes:
PHP (connection.php):
<?PHP
echo "haha";
?>
Javascript:
var testAjax = function(){
$.ajax({
url : 'connection.php',
type : 'POST',
data : {'name' : 'Ben'},
success : function(response){
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown){
console.log('jqXHR.responseText: ' + jqXHR.responseText);
console.log('jqXHR.responseXML : ' + jqXHR.responseXML);
console.log('textStatus: ' + textStatus);
console.log('errorThrown: ' + errorThrown);
},
dataType : 'text' //expected data type
});
}
Here, the I have type = 'POST'
. When I run testAjax()
on console, it gives me the following:
jquery-3.1.0.js:9392 POST https://(root address)/connection.php 404 (Not Found)send @ jquery-3.1.0.js:9392ajax @ jquery-3.1.0.js:8999testAjax @ script.js:63(anonymous function) @ VM3304:1
script.js:71 jqXHR.responseText: Cannot POST /jkeezie/homework-checker/WIP/connection.php
script.js:72 jqXHR.responseXML : undefined
script.js:73 textStatus: error
script.js:74 errorThrown: Not Found
However, when I change it to type = 'GET'
, and get rid of the data : {'name' : 'Ben'},
and run the same line on console, I get this:
<?PHP
echo "haha";
?>
The questions:
Why does it give me the 404 (first line of the response in the first scenario) when I use
type = 'POST'
and go through fine when I usetype = 'GET'
?Why does the second scenario return the entire PHP file content instead of just "haha" (without the quote marks).