My code is:
var test = \"it isn\'t working\";
var response = $.ajax({
type: \'GET\',
url: \'jquerydemo.php\', //This is in the same site as the page
Your ajax call is asynchronous. It has not completed yet when your alert at the end runs. Put an actual alert in the success function and you should see your result there.
Remember that making the ajax call just starts the asynchronous ajax call and then the rest of your code continues to run. In the code example you posted, that means your alert(test) call runs right away before the ajax call has completed.
You can ONLY examine the results of the ajax call from within the success handler itself.
var test = "it isn't working";
var response = $.ajax({
type: 'GET',
url: 'jquerydemo.php', //This is in the same site as the page calling this request, so it's not a same-domain error.
success: function(){
alert("it's working"); // put this here and you will see it
// if the ajax call is successful
},
error: function(){
alert("Error detected");
}
}).responseText;