I got a register page on my website, The problem is that i started to get this errors:
Uncaught TypeError: Cannot read property 'responseText' of undefined
Refused to set unsafe header "Content-length" register.php:1
Refused to set unsafe header "Connection"
Even without the last 2 errors (if i dont set the connection,content-length headers) i will get the first error.
For my ajax functionality i am using this function:
function AjaxLoad(xhr, url, cfunc, syn, method, headers, params)
{
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.onreadystatechange = cfunc; // This line take place on true/false
xhr.open(method, url, syn);
$.each(headers ,function(index, value){
xhr.setRequestHeader(index, value);
});
xhr.send(params);
}
At my js code i am calling the function like that:
var headersObject = {"Content-type" : "application/x-www-form-urlencoded", "Content-length" : userCap.val().length, "Connection" : "close" };
AjaxLoad(
xhr,
"../php/Ajax/captchaValidator.php",
getResponse,
false,
"POST",
headersObject,
userCap.attr("name") + "=" + encodeURIComponent(userCap.val())
);
AjaxLoad arguments explanation:
- xhr object
- location
- onreadystatechange handler
- Synchronous(its not working even if i will pass true)
- method
- headers
- key=value pair(I did test it so it get the right value)
This is the getResponse function:
function getResponse(){ var strongEl = capCon.next(); if(xhr.responseText == "0"){ if(strongEl.prop("tagName") == "STRONG"){ strongEl.getReplace('<strong id="sE">קוד שגוי</strong>'); }else{ capCon.after('<strong id="sE">קוד שגוי</strong>').next(); } bToSubmit = false; }else{ if(strongEl.prop("tagName") == "STRONG"){ strongEl.remove(); } } }
I test the network to see if the file captchaValidator.php is even get to the browser and i get status 200 everything seems ok.
I did test for right values, The code did worked before i dont know what changed, But this is the link to my website registration page Link, If you press send, You can see (in chrome browser at the network tab) that all is ok, But i get the errors i mentioned at the console tab, If some one can please take a look i will be very thankful.