jbadia
asked on
ajax problem in explorer 7, but not in firefox, inserting records
Hello, I have spent 4 days on my problem:
I have an online add TO Basket page where I see some products in php and MySql database.
Now I've implemented Ajax.
I have an ajax and javascript code that when I submit a product form, inserts a product in my basket (on the right of page.
It works fine in Firefox but not in explorer, and I answer to know WHY???
this is my ajax code:
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLH TTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.X MLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined ') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function enviarDatosEmpleado(){
divResultado = document.getElementById('r esultado') ;
id=document.frmempleado.id .value;
color=document.frmempleado .color.val ue;
talla=document.frmempleado .talla.val ue;
cantidad=document.frmemple ado.cantid ad.value;
marca=document.frmempleado .marca.val ue;
artId=document.frmempleado .artId.val ue;
pid=document.frmempleado.i d.value;
ajax=objetoAjax();
ajax.open("POST", "actu_Carrito.php",true);
ajax.onreadystatechange=fu nction() {
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Con tent-Type" ,"applicat ion/x-www- form-urlen coded");
ajax.send("id="+id+"&color ="+color+" &talla="+t alla+"&can tidad="+ca ntidad+"pi d="+pid+"m arca="+mar ca+"artId= "+artId)
}
In this page you can see my web application:
http://www.merc-barcelona.com/proves/mig.php?start=0&marca=27&artId=15&pid=486
When a submit the form I call the function 'enviarDatosEmpleado()' that inserts a cell in a mysql table and show again the basket.
I have this code into a page included into a php.
I can post the rest of the code for anyone who need it.
Thnks a lot.
Jordi
Barcelona
I have an online add TO Basket page where I see some products in php and MySql database.
Now I've implemented Ajax.
I have an ajax and javascript code that when I submit a product form, inserts a product in my basket (on the right of page.
It works fine in Firefox but not in explorer, and I answer to know WHY???
this is my ajax code:
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLH
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.X
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function enviarDatosEmpleado(){
divResultado = document.getElementById('r
id=document.frmempleado.id
color=document.frmempleado
talla=document.frmempleado
cantidad=document.frmemple
marca=document.frmempleado
artId=document.frmempleado
pid=document.frmempleado.i
ajax=objetoAjax();
ajax.open("POST", "actu_Carrito.php",true);
ajax.onreadystatechange=fu
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText
}
}
ajax.setRequestHeader("Con
ajax.send("id="+id+"&color
}
In this page you can see my web application:
http://www.merc-barcelona.com/proves/mig.php?start=0&marca=27&artId=15&pid=486
When a submit the form I call the function 'enviarDatosEmpleado()' that inserts a cell in a mysql table and show again the basket.
I have this code into a page included into a php.
I can post the rest of the code for anyone who need it.
Thnks a lot.
Jordi
Barcelona
>> IE7 has a native XMLHttpRequest object
True, but I have an application that fails when I try to use it; if I revert to the methods shown above - as if IE7 did *not* have built-in XMLHTTP support - then all is well.
True, but I have an application that fails when I try to use it; if I revert to the methods shown above - as if IE7 did *not* have built-in XMLHTTP support - then all is well.
ASKER
hernst42:
I have tried your new ajax code and don't go yet.
I remember that I have a first page called mig.php that includes some files like imgGranDetalls.php (where I have the form to send) and carritoV2.php (my basket). If I submit it inserts a new record into the basket. In firefox there's no problem but in IE7 it reloads the page and don't insert nothing.
It seems that don't recognize ajax.
BUT:
If I try to load ONLY the page imgGranDetalls.php (where's the form), then it goes right and inserts the record!
perhaps I forgot something.
Do you need that I post the code of tree pages?
Jordi
I have tried your new ajax code and don't go yet.
I remember that I have a first page called mig.php that includes some files like imgGranDetalls.php (where I have the form to send) and carritoV2.php (my basket). If I submit it inserts a new record into the basket. In firefox there's no problem but in IE7 it reloads the page and don't insert nothing.
It seems that don't recognize ajax.
BUT:
If I try to load ONLY the page imgGranDetalls.php (where's the form), then it goes right and inserts the record!
perhaps I forgot something.
Do you need that I post the code of tree pages?
Jordi
Have you ever resolved? I have the same problem in IE7, native support fails with permission denied. For me, if I reload the page then it works, it's only on the first page load that it fails.
IE has a limitation it can process not more than 2 simultaneously http requests, the work around for this is to create your xmlHTTP object instances, although you can also encapsulate the requests using an array and send one after the other. However, here are the guidelines which needs some work around for your purpose.
option 1
xmlhttp=new Array();
for(...){
var l=xmlhttp.length;
xmlhttp[l]=GetXmlHttpObjec t();
xmlhttp[l].open(...);
xmlhttp[l].onreadystatecha nge=functi on(){...};
xmlhttp[l].send(null);
}
option II
//this allows detection of XMLHttpRequest without crashing IE
try { new XMLHttpRequest() } catch(e) { XMLHttpRequest = null }
var xmlHttpReqQueue = new Array()
function requestXML(url) {
var xmlHttpReq
if (XMLHttpRequest) { //Mozilla
xmlHttpReq = new XMLHttpRequest()
xmlHttpReq.onload = function () {
xmlHttpReqQueue.shift()
//send the next request if queue isn't empty
if (xmlHttpReqQueue.length > 0)
xmlHttpReqQueue[0].send(nu ll)
doStuff()
}
} else if (window.ActiveXObject) { //IE
xmlHttpReq = new ActiveXObject('Msxml2.XMLH TTP')
xmlHttpReq.onreadystatecha nge = function () {
if (xmlHttpReq.readyState != 4)
return
xmlHttpReqQueue.shift()
//send the next request if queue isn't empty
if (xmlHttpReqQueue.length > 0)
xmlHttpReqQueue[0].send(nu ll)
doStuff()
}
}
xmlHttpReq.open('GET', url, true)
xmlHttpReqQueue.push(xmlHt tpReq)
//if queue was previously empty, there is no request being sent
//so send this request immediately
if (xmlHttpReqQueue.length == 1) {
xmlHttpReq.send(null)
}
}
option 1
xmlhttp=new Array();
for(...){
var l=xmlhttp.length;
xmlhttp[l]=GetXmlHttpObjec
xmlhttp[l].open(...);
xmlhttp[l].onreadystatecha
xmlhttp[l].send(null);
}
option II
//this allows detection of XMLHttpRequest without crashing IE
try { new XMLHttpRequest() } catch(e) { XMLHttpRequest = null }
var xmlHttpReqQueue = new Array()
function requestXML(url) {
var xmlHttpReq
if (XMLHttpRequest) { //Mozilla
xmlHttpReq = new XMLHttpRequest()
xmlHttpReq.onload = function () {
xmlHttpReqQueue.shift()
//send the next request if queue isn't empty
if (xmlHttpReqQueue.length > 0)
xmlHttpReqQueue[0].send(nu
doStuff()
}
} else if (window.ActiveXObject) { //IE
xmlHttpReq = new ActiveXObject('Msxml2.XMLH
xmlHttpReq.onreadystatecha
if (xmlHttpReq.readyState != 4)
return
xmlHttpReqQueue.shift()
//send the next request if queue isn't empty
if (xmlHttpReqQueue.length > 0)
xmlHttpReqQueue[0].send(nu
doStuff()
}
}
xmlHttpReq.open('GET', url, true)
xmlHttpReqQueue.push(xmlHt
//if queue was previously empty, there is no request being sent
//so send this request immediately
if (xmlHttpReqQueue.length == 1) {
xmlHttpReq.send(null)
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if ("undefined" != typeof XMLHttpRequest) {
xajax.tools.getRequestObje
return new XMLHttpRequest();
}
} else if ("undefined" != typeof ActiveXObject) {
xajax.tools.getRequestObje
try {
return new ActiveXObject("Msxml2.XMLH
} catch (e) {
xajax.tools.getRequestObje
try {
return new ActiveXObject("Msxml2.XMLH
} catch (e2) {
xajax.tools.getRequestObje
return new ActiveXObject("Microsoft.X
}
return xajax.tools.getRequestObje
}
}
return xajax.tools.getRequestObje
}
}
} else if (window.createRequest) {
xajax.tools.getRequestObje
return window.createRequest();
}
} else {
xajax.tools.getRequestObje
throw { name: 'GetRequestObject', message: 'XMLHttpRequest is not available, xajax is disabled' }
}
}