tags:

views:

39

answers:

2

I have following "jquery/javascript" code:

$.ajax({
    url: "PpbData",
    data: {RaidId: raidId},
    success: function(text) { $('input#PpbData').val(text); },
    dataType: 'text'
});

code 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)

A: 

Try this:

$.ajax({
    url: "PpbData",
    data: {RaidId: raidId},
    success: function(text) { if(text) { $('input#PpbData').val(text); } },
    dataType: 'text'
});
Dan D.
the problem is not in my function. It gives the error even if I got no `success` handler.
A: 

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.

jasonpgignac
The text returned is being inserted as a value into an <input type='text'> If I return "OK", it will have "OK" in the said field. Field is a blob-data meant for export into another program, I can't put "###no-data###" sort of data in there.