/    Sign up×
Community /Pin to ProfileBookmark

AJAX Javascript error

Hi…
I am having a problem with a short little javascript that I want to load information from the server – it works okay and does what it is supposed to UNLESS you remove the “Alert” line. I imagine using “alert” will cause some type of page refresh – as you can see the javascript parses the data prior to displaying it. Attached is the javascript code as well as the code for the page it calls – just in case somebody needs to work with it

can anybody give me a hint?

Thank you

P.J.

Here is the code:


—–

<body onload=”pageDataLoad()”>

<div id=”serverData” style=”display: none”>
<div id=”returnData”></div>
</div>
<div id=”tempOutput”>smoo</div>

<script language=”javascript”>

function pageDataLoad(){

ajaxLoadData(‘ajax_port.aspx?searchTerm=faro&’,’serverData’);
onServerDataLoad();
}

function ajaxLoadData(url,id) {
if (document.getElementById) {
var x = (window.ActiveXObject) ? new ActiveXObject(“Microsoft.XMLHTTP”) : new XMLHttpRequest();
}
if (x) {
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) {
el = document.getElementById(“serverData”);
el.innerHTML = x.responseText;
}
}

x.open(“GET”, url, true);
x.send(null);

}
}

function onServerDataLoad(){

var myout;
var lclItem;
var itemArray;
var lclObj;

myout = “”;

// it does nto work properly without the following line of code
[COLOR=”Red”][B]alert(“serverData”)[/B][/COLOR]
// everything will work if this is not there.

for(lclItem in returnData.all){
if(lclItem != “length”){

itemArray = document.getElementById(lclItem)
myout = myout + lclItem + ” = ” + itemArray.innerHTML + “<br />n”;

}
}
tempOutput.innerHTML = myout;
}

</script>
—–

Also here is the code for commpage.html

<div name=”returnHeader” id=”returnHeader”>
<span id=”fieldCount”>3</span>
</div>
<div name=”returnData” id=”returnData”>
<span id=”myMessage”>This is a message</span>
<span id=”myName”>FARO Webmaster</span>
<span id=”testField”>This is some data.</span>
</div>
<script language=”javascript”>
parent.confirmData();
</script>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @FAROwebmaster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...