I do ajax call via new XMLHttpRequest();
when I do this
var params = "x="+encodeURIComponent(x);
var xhr = new XMLHttpRequest();
xhr.open("POST", "....php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
$("#divID").html(e.currentTarget.responseText);
}
}
xhr.send(params);
It is fine and working well….. but when the result contains @ I get this error in console log
Uncaught TypeError: Cannot read property 'removeChild' of null without using removeChild
to clarify : example :
when the php gives <img src="..." />
–>> it’s ok
when the php gives some text blablabla ...blalbla contact [email protected]
–>> I get the error
why and do I need to fix it ???
Regards
2
Answers
I found a "workable" solution
in the php of the ajax call I do only one echo and replace any occurence of @ to &commat
that way the browser shows @ and the error don't appear in console log
note : I tried to replace in javascript level (e.currentTarget.responseText) but it didn't worked.
As in ajax you are sending plain html code. I would suggest you to use the json format
on ajax response. this will solve your problem