I have the开发者_开发技巧 following code.
$.ajax({
type: "POST",
url:"blahblah.php",
data: "{}",
async: true,
dataType: "text",
success: function() {
if(returning data from blahblah.php == true)
window.location.href="http://www.blahblah.com/logout.php";
}
});
1) No data need to be sent.
2) File "blahblah.php" does some processing and returns either true or false.
3) I want to get the response and If true redirect to another php page.
I do not know how to read the returning data of the function in the blahblah.php file!!
Thank you in advance. George
You have to pass a variable into the success
call.
$.ajax({
type: "POST",
url:"blahblah.php",
data: "{}",
async: true,
dataType: "text",
success: function( data ) {
console.log(data);
}
});
If the success method runs then you have successfully submitted the file and can redirect with a simple document.location = "http://www.example.com/somewhere.php
Have you tried setting dataType to 'json'
?
Also, you're not actually retrieving the response from the server on a successful callback. Try this:
$.ajax({
type: "POST",
url:"blahblah.php",
data: "{}",
async: true,
dataType: "json",
success: function(response) {
if(response == true) {
window.location.href="http://www.blahblah.com/logout.php";
}
}
});
If your success event is not call then you may be get return data using complete event
example
complete: function (data) {
alert(data.responseText);
},
using this you can get response data in this event
精彩评论