开发者

Deal with jQuery.ajax empty content response

开发者 https://www.devze.com 2023-01-06 11:01 出处:网络
I have following \"jquery/javascript\" code: $.ajax({ url: \"PpbData\", data: {RaidId: raidId}, success: function(text) { $(\'input#PpbData\').val(text); },

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消