Ajaxthe combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I am handling the project now, I try my first ajax application with the wrox.professional.ajax.2nd edition..
it use zxml.js as a library tp create xml object, its work fine in FF, Chrome, opera, and safari..
but in IE, it gets an error says
"Object doesn't support this property or method"
zxml.js Line: 96
Code: 0 Char: 9
but, if I click f5(refresh) button to refresh the page, its work fine..
I am very confuse for this trouble, I suggest that user certainly won't click f5 every visit the page, therefore user will get an error if the user use IE browser.. please help me.. all the web master..
I am not understand about the code has execute before load..
hmm, this is my code
competition_photo_list.php
--------------------------------
<script type="text/javascript"src="ajax/zxml.js"></script>
<script language="javascript">
function vote(photo_id,competition_id,vote_type,i){
competition_url = document.getElementById("competition_url_form").ac tion;
var oXHR = zXmlHttp.createRequest();
oXHR.open("get", competition_url+"/set_favorite"+"/"+photo_id+"/"+competition_id+"/"+vote_type, true);
oXHR.onreadystatechange = function () {
/*
0 (Uninitialized): The object has been created but the open() method hasn’t been called.
1 (Loading): The open() method has been called but the request hasn’t been sent.
2 (Loaded): The request has been sent.
3 (Interactive). A partial response has been received.
4 (Completed): All data has been received and the connection has been closed.
*/
if (oXHR.readyState == 4) {
if (oXHR.status == 200 || oXHR.status == 304){
if(oXHR.responseText == "insert"){
on_click = 'vote('+photo_id+','+competition_id+',2,'+i+')';
text = "not favorite";
}
displayCustomerInfo(text,i,on_click);
} else {
displayCustomerInfo("An error occurred: " + oXHR.statusText,i); //statusText is not always accurate
}
}else if(oXHR.readyState == 1){
displayCustomerInfo("loading...",i);
}
};
oXHR.send(null);
}
function displayCustomerInfo(text,i,onclickFunction){
var divCustomerInfo = document.getElementById("vote"+i);
if(onclickFunction != null){
divCustomerInfo.onclick = Function(onclickFunction);
}
divCustomerInfo.innerHTML = text;
}
Maybe this the explanation..
I want Make "favorite" or "not favorite" like we can see on faceb**k with "like" or "dislike",
so I detect with onclick to go to vote function..
vote function get 4 parameter (photo_id, competition_id, type_vote, i)
photo_id -> photo thats want to be voted
competition_id -> the photo is in this competition
vote_type -> 1=>"favorite" and 2=> "not favorite"
i -> number of id in every div.
and the error if I dont use f5 to refresh the page, is in zxml.js line 96..
the error line is like this :
zXmlHttp.createRequest = function ()/*:XMLHttp*/ {
if (zXml.settings.hasXmlHttp) {
return new XMLHttpRequest(); //this is line 96, and IE say this is error with error message [Object doesn't support this property or method]
} else if (zXml.settings.hasActiveX) {
if (!zXml.XMLHTTP_VER) {
for (var i=0; i < zXml.ARR_XMLHTTP_VERS.length; i++) {
try {
new ActiveXObject(zXml.ARR_XMLHTTP_VERS[i]);
zXml.XMLHTTP_VER = zXml.ARR_XMLHTTP_VERS[i];
break;
} catch (oError) {
}
}
}
if (zXml.XMLHTTP_VER) {
return new ActiveXObject(zXml.XMLHTTP_VER);
} else {
throw new Error("Could not create XML HTTP Request.");
}
} else {
throw new Error("Your browser doesn't support an XML HTTP Request.");
}
};
function vote(photo_id,competition_id,vote_type,i){
competition_url = document.getElementById("competition_url_form").ac tion;
var oXHR = zXmlHttp.createRequest();
oXHR.open("get", competition_url+"/set_favorite"+"/"+photo_id+"/"+competition_id+"/"+vote_type, true);
oXHR.onreadystatechange = function () {
/*
0 (Uninitialized): The object has been created but the open() method hasn’t been called.
1 (Loading): The open() method has been called but the request hasn’t been sent.
2 (Loaded): The request has been sent.
3 (Interactive). A partial response has been received.
4 (Completed): All data has been received and the connection has been closed.
*/
if (oXHR.readyState == 4) {
if (oXHR.status == 200 || oXHR.status == 304){
if(oXHR.responseText == "insert"){
on_click = 'vote('+photo_id+','+competition_id+',2,'+i+')';
text = "not favorite";
}
displayCustomerInfo(text,i,on_click);
} else {
displayCustomerInfo("An error occurred: " + oXHR.statusText,i); //statusText is not always accurate
}
}else if(oXHR.readyState == 1){
displayCustomerInfo("loading...",i);
}
};
oXHR.send(null);
}
function displayCustomerInfo(text,i,onclickFunction){
var divCustomerInfo = document.getElementById("vote"+i);
if(onclickFunction != null){
divCustomerInfo.onclick = Function(onclickFunction);
}
divCustomerInfo.innerHTML = text;
}
Maybe this the explanation..
I want Make "favorite" or "not favorite" like we can see on faceb**k with "like" or "dislike",
so I detect with onclick to go to vote function..
vote function get 4 parameter (photo_id, competition_id, type_vote, i)
photo_id -> photo thats want to be voted
competition_id -> the photo is in this competition
vote_type -> 1=>"favorite" and 2=> "not favorite"
i -> number of id in every div.
and the error if I dont use f5 to refresh the page, is in zxml.js line 96..
the error line is like this :
zXmlHttp.createRequest = function ()/*:XMLHttp*/ {
if (zXml.settings.hasXmlHttp) {
return new XMLHttpRequest(); //this is line 96, and IE say this is error with error message [Object doesn't support this property or method]
} else if (zXml.settings.hasActiveX) {
if (!zXml.XMLHTTP_VER) {
for (var i=0; i < zXml.ARR_XMLHTTP_VERS.length; i++) {
try {
new ActiveXObject(zXml.ARR_XMLHTTP_VERS[i]);
zXml.XMLHTTP_VER = zXml.ARR_XMLHTTP_VERS[i];
break;
} catch (oError) {
}
}
}
if (zXml.XMLHTTP_VER) {
return new ActiveXObject(zXml.XMLHTTP_VER);
} else {
throw new Error("Could not create XML HTTP Request.");
}
} else {
throw new Error("Your browser doesn't support an XML HTTP Request.");
}
};
yeah I know where is my problem, I always get this problem in IE, but I just realize this..
In my <head> tag of HTML I use jquery for menu, so I add this script
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> // if I replace this line, It will be okay.. but the menu won't work as usual...
I always get this problem because I use Many jquery in my web..
At the past, I call jquery.min.js twice because I use different jquery plugins which both needs that jquery, at that time I realize that and I can resolve that, but now I confuse how to resolve this.. its strange why only IE give me error like this... maybe there is the explanation from someone who can help me..
One thing that I want to know is, why IE debug this code like that? why only the sequence like that must require user to click f5 button to run well. ?
thank for the reply imar anyway.. I am very appreciate with your help before..