Javascript 从ajax响应中删除尾部0
我知道还有一个问题,但我认为这可能不是wordpress的特定问题:Javascript 从ajax响应中删除尾部0,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我知道还有一个问题,但我认为这可能不是wordpress的特定问题: $.get( ajax.url, { 'action': 'ajax', }, function( response, status, xhr ) { $('ul.event-items').append(response); } ); 我正在调用一个常规的wordpress函数,其中没有0或其他任何内容 然而,在每次ajax请求之后,我都会
$.get(
ajax.url,
{
'action': 'ajax',
},
function( response, status, xhr ) {
$('ul.event-items').append(response);
}
);
我正在调用一个常规的wordpress函数,其中没有0或其他任何内容
然而,在每次ajax请求之后,我都会在文档中附加一个尾随零
我怎样才能解决这个问题?我试着使用die()代码>在我的函数中,但是在这种情况下,脚本的其余部分将不会被渲染
是否有一个简单的JS修复程序,比如subsrting(),可以从我的html响应中删除尾随的0
亲切问候,,
马特
试试这个:
...
$('ul.event-items').append(response.substr(response.length-1, 1) === '0'? response.substr(0, response.length-1) : response);
该文档在php函数的末尾使用了wp_die()
,以防止出现0(可能还有其他问题)
您能显示字符串吗?还可以尝试找出任何不需要的回显语句。您可以使用条件js substr()
,检查最后一个字符是否为“0”,并将其删除。我想知道它是从哪里来的,因为它以后可能会变成其他东西。如果你使用WordPress,这是正确的答案。这是正确的答案!
...
$('ul.event-items').append(response.substr(response.length-1, 1) === '0'? response.substr(0, response.length-1) : response);
"wp_die(); // this is required to terminate immediately and return a proper response"