Is it possible to post from a PHP file to a JS to a PHP and get the results from the external PHP file to the JS file that posted the information? I don't what to get back that it's a success - I want to get what's echoed from the actual content from the PHP file that processes it.
Here's the code that I have:
$(function() {
$(".deletebutton").click(function() {
$.ajax({
type: "POST",
url: "*****/process_delete.php",
data: dataString,
success: function() {
// Get results from form here
}
});
return false;
});
});
Haven't found anywhere where this is possible, is it? If s开发者_StackOverflowo, please post some example code!
Thanks!
CoultonThe success
function receives the data that the server returned as its first parameter
$.ajax({
type: "POST",
url: "*****/process_delete.php",
data: dataString,
success: function(data) {
// do something with data here
}
});
You can use the dataType
attribute of your $.ajax
object to ensure you get the data back in the format you expect. So if process_delete.php is returning JSON, for example:
$.ajax({
type: "POST",
url: "*****/process_delete.php",
data: dataString,
success: function(data) {
// do something with data here
},
dataType: "json" // The data string will be returned as a JavaScript object.
});
Change your success callback to look like this:
success: function (data) {
// data = the response from the server
}
Or am I misunderstanding the question?
EDIT
I think I see you mentioned that you're using JSON as well. If you want jQuery to automatically parse the response text into a JavaScript Object, then add dataType: "json"
to your $.ajax
configuration.
$.ajax({
type: "POST",
url: "*****/process_delete.php",
data: dataString,
dataType: "json", // or use "text json" if that doesn't work
success: function() {
// Get results from form here
}
});
精彩评论