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