Reputation:
Ok, so I'm submitting a form and posting an ajax call as follows:
$('#pForm').on('submit', function(e) {
e.preventDefault(); //Prevents default submit
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
$.ajax({
type: 'POST',
url: 'calc.php',
data: post_data,
success: function() {
// show the result
}
});
});
This fires off to calc.php
which performs a quick calculation based on the values in various fields of the form. The end result is a variable $result
in calc.php
. How do I access this in my ajax code to display it, just an alert for now is fine...
Thanks
Upvotes: 1
Views: 69
Reputation: 875
$('#pForm').on('submit', function(e) {
e.preventDefault(); //Prevents default submit
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
$.ajax({
type: 'POST',
url: 'calc.php',
data: post_data,
success: function(html) {
$("someplace").html(html);
}
});
});
Upvotes: 1
Reputation: 6344
$.ajax({
.......
success: function(data) { // here data holds your response
// show the result
alert(data);
}
});
Find more info here
Upvotes: 1
Reputation: 22711
You can get the results using as below,
success: function(result) {
// show the result
console.log(result);
}
Upvotes: 1