Reputation: 1159
trying to learn to use AJAX on a form (using the AJAXForm plugin) to then be processed with PHP and am having a lot of trouble.
Basically, I have a form with a bunch of fields that I want to passed through an AJAX call to some page that will process it. Here is my form:
<form action="" method="post" id="aligned" class='add'>
. . . . .yadda yadda yadda. . . .
<button type='submit' class='btn btn-primary'>Add</button>
</form>
And at the bottom of the page, I have:
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('.add').ajaxForm(function() {
alert("Thank you for your comment!");
});
$('.add').ajaxForm({
url: this.href, type:'post',
data: this.serialize()+'&action=update',
success: function(){alert('ok'+responseText.text);},
error: function(){alert('ok'+responseText.text);}
});
});
The first ajaxForm function works on cue, so I must be doing something wrong with the way I'm doing the second one, even though I am trying to follow different examples I found online.
I don't have much going on in the PHP page--just a simple 'echo'.
(-Do I need to do something to set it to success/error (and because I'm not is why it's not doing anything)? -Is my format wrong? -Is responseText.text not the right way to get theecho'ed back information?)
Upvotes: 0
Views: 797
Reputation: 4443
I see error in your code,you need add responseText in signature of function
success: function(responseText){alert('ok'+responseText.text);},
error: function(responseText){alert('ok'+responseText.text);}
Upvotes: 1