admin管理员组文章数量:1356946
I know there is also however I think this is probablynot a wordpress specific question:
$.get(
ajax.url,
{
'action': 'ajax',
},
function( response, status, xhr ) {
$('ul.event-items').append(response);
}
);
I'm calling a regular wordpress function that has no 0 in it or whatsoever.
However after every ajax-request I get a trailing zero appended to my document.
How can I fix this? I tried using die();
in my function however the rest of my script will not get rendered in that case.
Is there an easy JS-fix like subsrting() to remove the trailing 0 from my html response?
Kind regards, Matt
I know there is also http://wordpress.stackexchange. however I think this is probablynot a wordpress specific question:
$.get(
ajax.url,
{
'action': 'ajax',
},
function( response, status, xhr ) {
$('ul.event-items').append(response);
}
);
I'm calling a regular wordpress function that has no 0 in it or whatsoever.
However after every ajax-request I get a trailing zero appended to my document.
How can I fix this? I tried using die();
in my function however the rest of my script will not get rendered in that case.
Is there an easy JS-fix like subsrting() to remove the trailing 0 from my html response?
Kind regards, Matt
Share Improve this question edited Jan 8, 2016 at 15:33 hindmost 7,1803 gold badges32 silver badges41 bronze badges asked Jan 26, 2014 at 18:14 mattmatt 44.5k107 gold badges268 silver badges402 bronze badges 2- can you show the string? also try to find out any unwanted echo statements – Nouphal.M Commented Jan 26, 2014 at 18:21
-
You could use a conditional
js substr()
and check if the last character is '0' and lop it off it is. I'd wanna know where its ing from though, cause it might turn into something else later on. – dgo Commented Jan 26, 2014 at 18:26
3 Answers
Reset to default 10The documentation uses wp_die()
at the end of the php function to prevent the 0 (and presumably other problems too).
"wp_die(); // this is required to terminate immediately and return a proper response"
Link to docs
Try this:
...
$('ul.event-items').append(response.substr(response.length-1, 1) === '0'? response.substr(0, response.length-1) : response);
http://www.w3schools./jsref/jsref_substring.asp
Example
Extract characters from a string:
var str = "Hello world!";
var res = str.substring(1,4);
The result of res will be:
ell
本文标签: javascriptRemove trailing 0 from ajaxresponseStack Overflow
版权声明:本文标题:javascript - Remove trailing 0 from ajax-response - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743966881a2570031.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论