Reputation: 17573
I'm using jquery with the jquery form plugin. I read through a bunch of posts, the docs, etc., and I'm still having trouble with what I believe to be simple. I have a form with some simple text inputs and a couple textareas, and I have this link that I want to trigger submission of that form to a specific method (/email):
<a id="email-data">Send Email</a>
and this jquery in doc ready:
$('#email-data').click(function() {
var options = {
url: '/email/',
success: alert('Email sent.')
};
$('#report-giftcard-sales-form').ajaxSubmit(options);
});
So I would expect it to submit to my /email method, but no such luck. Currently I just have the /email method logging a debug message, so it's as simple as can be.
Any help is greatly appreciated.
Upvotes: 0
Views: 504
Reputation: 17573
Answering my own question here...
Hey stupid, yes you (a.k.a. me), you need to load jquery BEFORE you load a jquery plugin!
(I of course know this. Sometimes stupidity just happens when you're working too fast)
Good Example:
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.form.js"></script>
Upvotes: 1
Reputation: 27765
Callback from success
option can't be alert because it require more than one param at the callback function. You need to write something like this:
$('#email-data').click(function() {
var options = {
url: '/email/',
success: formSended
};
$('#report-giftcard-sales-form').ajaxSubmit(options);
});
function formSended(responseText, statusText, xhr, $form) {
alert('Email sent.Status: '+statusText);
}
Upvotes: 1