Hi there,
I´m stuck with a problem and hopefully you can help me:
I am using ajax for a login form and need to return the feedback of the php code used at 2 different divs. So I thought I would let the php script return one text block that I would then split by javascript and pass each of the 2 blocks to the respective div, but somehow I can´t make it work.
Here is the code I use (thx go to Simone Rodriguez):
Now I was able to hunt the problem down that it obviously occurs between the alert box 1 and the alert box 2, which means on my screen keeps the ajax loading graphic, but the data wouldn´t be updated to the divs.
Now the update function is that (but I checked it and it works):
I would be really glad to get some pointers. Obviously the error needs to be happening at declaring the var, but since I am new to JS I cannot see an error there...
Thx :)
I´m stuck with a problem and hopefully you can help me:
I am using ajax for a login form and need to return the feedback of the php code used at 2 different divs. So I thought I would let the php script return one text block that I would then split by javascript and pass each of the 2 blocks to the respective div, but somehow I can´t make it work.
Here is the code I use (thx go to Simone Rodriguez):
Code:
function xmlhttpPost(strURL,formname,responsemsg,responsediv,responsediv2) {
var xmlHttpReq = false;
var self = this;
// Xhr per Mozilla/Safari/Ie7
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// per tutte le altre versioni di IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
// Quando pronta, visualizzo la risposta del form
window.alert("1");
var siteFeedback = xmlHttp.responseText;
window.alert("2");
sfArr = siteFeedback.split("||");
updatepage(sfArr[0],responsediv);
if (sfArr[1] != null)
{
updatepage(sfArr[1],responsediv2);
}
}
else{
// In attesa della risposta del form visualizzo il msg di attesa
updatepage(responsemsg,responsediv);
}
}
self.xmlHttpReq.send(getquerystring(formname));
}
Now the update function is that (but I checked it and it works):
Code:
function updatepage(str,responsediv){
window.scrollTo(0,0);
document.getElementById(responsediv).innerHTML = str;
}
Thx :)
Comment