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;
}
and the HTML snippet is like this :
<div class="vote" id="vote0" onclick="vote(11,2,1,0)">favorite</div>
<div class="vote" id="vote1" onclick="vote(10,2,2,1)">favorite</div>
<div class="vote" id="vote2" onclick="vote(16,2,1,2)">favorite</div>
<div class="vote" id="vote3" onclick="vote(18,2,2,3)">favorite</div>
<div class="vote" id="vote4" onclick="vote(17,2,1,4)">favorite</div>
<div class="vote" id="vote5" onclick="vote(19,2,2,5)">favorite</div>
<div class="vote" id="vote6" onclick="vote(18,2,1,6)">favorite</div>
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.");
}
};