Reputation: 113
I'm trying to build a custom function for ajax but the output is "null"
$("form[id*='admin-handler/announcements'] #submit").click(function(e) {
e.preventDefault();
ajaxCall("/admin-handler/announcements", $(this).serialize(), function(data) {
alert(data);
});
});
function ajaxCall(_url, _data, callback) {
$.ajax({
type: "POST",
url: _url,
data: _data,
dataType: 'json',
success: function(data) {
callback(data);
}
});
}
so.. what's wrong with my code?
Upvotes: 0
Views: 74
Reputation: 53198
$(this).serialize()
in your argument list will try to serialize #submit
, not the form
element to which it belongs.
And since you're accessing #submit
via its ID, the preceding form
selector should be redundant.
Upvotes: 6