Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2010, 10:27 AM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default plis help, Error in IE, must refresh the page(f5)

I want ask everyone to help my problem..please..

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..
 
Old August 18th, 2010, 12:25 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Maybe the code already executes before external JavaScript files are fully loaded?

But it's hard to tell, without source code.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
edidiway (August 19th, 2010)
 
Old August 18th, 2010, 02:44 PM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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.");
}
};
 
Old August 18th, 2010, 02:47 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hard to tell as I don't know what zXml.settings is, and what it's supposed to do.

Is it your own script? Have you tried debugging it?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 18th, 2010, 02:48 PM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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.");
}
};
 
Old August 18th, 2010, 02:53 PM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Hard to tell as I don't know what zXml.settings is, and what it's supposed to do.

Is it your own script? Have you tried debugging it?

Imar
no, zxml.js is not my own script, I get it from the tutorial of wrox.professional.ajax.2nd edition...

so I dont understand why it is error in IE..
 
Old August 18th, 2010, 02:54 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Neither do I..... ;-)

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old August 18th, 2010, 03:24 PM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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...

<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.metadata.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/mbMenu.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.hoverIntent.js"></script>


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..
 
Old August 19th, 2010, 01:30 AM
Registered User
 
Join Date: Jun 2010
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Talking

okay, my problem was fixed.. I am very happy.. hahaha


hm, but I don't understand at all why it's error in IE if I don't click f5 button...

my mistake was I put meta tag [<meta />] and title tag [<title></title>] after the javascript tag <script></script> like this :

<head>
<!-- for menu jquery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.metadata.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/mbMenu.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.hoverIntent.js"></script>
<script type="text/javascript" >
$(function(){
$(".myMenu").buildMenu({
template:"menuVoices.html",
additionalData:"pippo=1",
menuWidth:200,
openOnRight:false,
menuSelector: ".menuContainer",
iconPath:"ico/",
hasImages:true,
fadeInTime:100,
fadeOutTime:300,
adjustLeft:2,
minZindex:"auto",
adjustTop:10,
opacity:.95,
shadow:true,
openOnClick:true,
closeOnMouseOut:true,
closeAfter:1000
});
});
</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
</head>


And when I change the sequence like this, It's run very well in IE without user must click f5 button :

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home</title>
<!-- for menu jquery -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.metadata.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/mbMenu.js"></script>
<script type="text/javascript" src="<?=base_url()?>plugins/jquery.mb.menu.2.8.5/inc/jquery.hoverIntent.js"></script>
<script type="text/javascript" >
$(function(){
$(".myMenu").buildMenu({
template:"menuVoices.html",
additionalData:"pippo=1",
menuWidth:200,
openOnRight:false,
menuSelector: ".menuContainer",
iconPath:"ico/",
hasImages:true,
fadeInTime:100,
fadeOutTime:300,
adjustLeft:2,
minZindex:"auto",
adjustTop:10,
opacity:.95,
shadow:true,
openOnClick:true,
closeOnMouseOut:true,
closeAfter:1000
});
});
</script>

</head>


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..





Similar Threads
Thread Thread Starter Forum Replies Last Post
hit F5 refresh triggers again the query cp75 Beginning PHP 2 September 25th, 2008 01:12 AM
Chapter 1 Ctrl+F5 don't work, F5 does work? jimboak BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 June 29th, 2008 03:46 AM
F5 (Refresh) adds a new record after postback krainov BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 November 20th, 2007 10:10 AM
Reloading page with Ctrl+F5 aliirfan84 ASP.NET 2.0 Professional 1 October 10th, 2007 07:19 AM
Error when refresh the page! heba ASP.NET 2.0 Professional 3 June 6th, 2007 08:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.