0

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?

asked Oct 5, 2012 at 19:17
2
  • 1
    You should check in your developer tools, under Network, what you receive from your server first. Commented Oct 5, 2012 at 19:20
  • What appens when you go to /admin-handler/announcements manually in a browser? I assume that is returning you a JSON string and all working OK? Commented Oct 5, 2012 at 19:21

1 Answer 1

6

$(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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.