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?
1 Answer 1
$(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.
answered Oct 5, 2012 at 19:20
BenM
53.3k26 gold badges116 silver badges172 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
Network, what you receive from your server first.