处理jQuery.ajax空内容响应

时间:2021-10-09 07:42:40

I have following "jquery/javascript" code:

我有以下“jquery / javascript”代码:

$.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.

代码使用AJAX从服务器更新文本框。有用。但是当响应为空字符串时 - 我在firefox控制台中找不到'找不到元素'。没什么大不了的,但我想摆脱警告。

Using asp.net mvc I generate response as follows: return Content("");

使用asp.net mvc我生成响应如下: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)

什么是一个简单而优雅的方法来解决它? (我想出了几个黑客,但我不想要黑客入侵)

2 个解决方案

#1


0  

Try this:

尝试这个:

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

#2


0  

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.

或者你可以提供一些内容。例如,Rails脚手架控制器在成功的无响应AJAX调用中返回“OK”作为文本内容。为您提供简单的测试。

#1


0  

Try this:

尝试这个:

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

#2


0  

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.

或者你可以提供一些内容。例如,Rails脚手架控制器在成功的无响应AJAX调用中返回“OK”作为文本内容。为您提供简单的测试。