Reputation: 27
I have a strange problem, I am performing a simple application process with jquery $ post json, however, nothing is returned, see below how did the codes.:
application.js:
(function($){ $(document).on('submit', "form", function() { var a = $(this); if(jQuery().validate) { $('#'+a.attr('id')).validate({ success: 'valid', submitHandler: function() { $.post(a.attr('action'), $('#'+a.attr('id')).serialize(), function(r) { if(jQuery.ui) { $('#msn').attr('title',r.resp); $('#msn').html(r.msn); $("#msn").dialog({ width: 350, height: 135, modal: true }); $("#msn").dialog("open"); } else { alert(r.msn); } }, 'json'); } }); } else { console.log('ok'); } return false; }); $('form').submit(); })(jQuery);
controller.php
echo json_encode(array( 'resp' => 'ok', 'msn' => 'registered successfully' ));
Upvotes: 0
Views: 134
Reputation: 27
I found the answer and can not believe the file was in Unicode signature (BOM) enabled and that prevented the file correctly return the json.
Upvotes: 0