Deal with jQuery.ajax empty content response
I have following "jquery/javascript" code:
$.ajax({
url: "PpbData",
data: {RaidId: raidId},
success: function(text) { $('input#PpbData').val(text); },
dataType: 'text'
});
cod开发者_如何学编程e updates a textbox from server using AJAX. It works. But when the response is empty string - I get 'no element found' in firefox console.
Not a big deal, but I'd like to get rid of the warning.Using asp.net mvc I generate response as follows: return Content("");
What would be a simple and elegant way to fix it? (I came up with few hacks, but I don't want a hack)
Try this:
$.ajax({
url: "PpbData",
data: {RaidId: raidId},
success: function(text) { if(text) { $('input#PpbData').val(text); } },
dataType: 'text'
});
Or you could just provide some content. Rails scaffold controllers, for instance, return "OK" as the text content on a successful, responseless AJAX call. Gives you an easy test.
精彩评论