473,587 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX innerHTML problem

The full code relating to this question can be found at
http://marc.info/?l=php-general&m=112198633625636&w=2

It describes a bare bones way of making an AJAX request.
It works fine for me except at the last step where data is put into an
innerHTML element within
<div id="foo">
</div>

Here is the function to do that:

function handleResponse( ) {
if(http.readySt ate == 4){
var response = http.responseTe xt;
var update = new Array();
// var up0 = update[0];
// alert("up0 is " + up0);
if(response.ind exOf('|' != -1)) {
update = response.split( '|');
document.getEle mentById(update[0]).innerHTML = update[1];
}
}
}

I get an error stating that getElementById( update[0]) is either null
or not an object>

Using the commented out alert code I have confirmed that the update
array does in fact contain "foo" in update[0].

If I hardcode the value "foo" into the line thus
document.getEle mentById("foo") .innerHTML = update[1];

update[1] is displayed ok within the foo div without error
I would be gratefulif somone could explain to me what is causing this
error

TIA
N
Mar 20 '07 #1
5 3837
noddy wrote:
The full code relating to this question can be found at
http://marc.info/?l=php-general&m=112198633625636&w=2

It describes a bare bones way of making an AJAX request.
It works fine for me except at the last step where data is put into an
innerHTML element within
<div id="foo">
</div>

Here is the function to do that:

function handleResponse( ) {
if(http.readySt ate == 4){
var response = http.responseTe xt;
var update = new Array();
// var up0 = update[0];
// alert("up0 is " + up0);
if(response.ind exOf('|' != -1)) {
update = response.split( '|');
document.getEle mentById(update[0]).innerHTML = update[1];
}
}
}

I get an error stating that getElementById( update[0]) is either null
or not an object>

Using the commented out alert code I have confirmed that the update
array does in fact contain "foo" in update[0].

If I hardcode the value "foo" into the line thus
document.getEle mentById("foo") .innerHTML = update[1];

update[1] is displayed ok within the foo div without error
I would be gratefulif somone could explain to me what is causing this
error
Hi,

This has nothing to do with AJAX.

Just alert (http.responseT ext);
to see what the response contains.
According to your code it should contain at least one |
I expect it doesn't.

an example:
var test = "one|two";
var myArr = test.split("|") ;
alert (myArr[0]);
alert (myArr[0]);
alert (myArr[2]);

The last alert will fail because the element is never filled by the split
return array since it contains only 2 elements.

I expect you have a similar problem in your responsetext.

In general: Always examine the response from an Ajax request.

Regards,
Erwin Moller
>
TIA
N
Mar 20 '07 #2
On Mar 20, 6:52 am, noddy <n...@toyland.c omwrote:
The full code relating to this question can be found athttp://marc.info/?l=php-general&m=11219 8633625636&w=2

It describes a bare bones way of making an AJAX request.
It works fine for me except at the last step where data is put into an
innerHTML element within
<div id="foo">
</div>

Here is the function to do that:

function handleResponse( ) {
if(http.readySt ate == 4){
var response = http.responseTe xt;
var update = new Array();
// var up0 = update[0];
// alert("up0 is " + up0);
if(response.ind exOf('|' != -1)) {
Oops... should be if (response.index Of('|') >= 0) {

update = response.split( '|');
document.getEle mentById(update[0]).innerHTML = update[1];
You should confirm that the length of the array is also 2:

if (update.length >= 2) {
document.getEle mentById(update[0]).innerHTML = update[1];
}
}
}

}

I get an error stating that getElementById( update[0]) is either null
or not an object>

Using the commented out alert code I have confirmed that the update
array does in fact contain "foo" in update[0].

If I hardcode the value "foo" into the line thus
document.getEle mentById("foo") .innerHTML = update[1];

update[1] is displayed ok within the foo div without error

I would be gratefulif somone could explain to me what is causing this
error

TIA
N

Mar 20 '07 #3
On Tue, 20 Mar 2007 12:51:52 +0100, Erwin Moller
<si************ *************** *************** @spamyourself.c omwrote:
>Hi,

This has nothing to do with AJAX.
You are right - I am resending the query more appropriatelyhe ad
>Just alert (http.responseT ext);
to see what the response contains.
According to your code it should contain at least one |
I expect it doesn't.
Thank you but it does

N


Mar 21 '07 #4
On 20 Mar 2007 05:52:36 -0700, "Tom Cole" <tc****@gmail.c omwrote:

> if(response.ind exOf('|' != -1)) {

Oops... should be if (response.index Of('|') >= 0) {
Really?
This line as it is seems to confirm the presence orabsence of | in
the string just fine
>
> update = response.split( '|');
document.getEle mentById(update[0]).innerHTML = update[1];

You should confirm that the length of the array is also 2:
The length of the array is 2 .
Thanks for your response.

N
Mar 21 '07 #5
noddy said the following on 3/21/2007 12:00 AM:
On 20 Mar 2007 05:52:36 -0700, "Tom Cole" <tc****@gmail.c omwrote:

>> if(response.ind exOf('|' != -1)) {
Oops... should be if (response.index Of('|') >= 0) {

Really?
This line as it is seems to confirm the presence orabsence of | in
the string just fine
No, it doesn't test the presence of |, it checks the presence of '|' !=
-1 You need to move the equality comparison outside the parentheses of
the indexOf search.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
1867
by: Joel Byrd | last post by:
I am making an AJAX call when any one of a number of inputs in a form (search criteria) are clicked, checked, changed, etc. When the user clicks, checks, whatever, I am trying to display a "Retrieving results..." text. This should be really simple, but in IE, it does not work. Here's the code that is not executing in IE: And here is...
17
11855
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);" onclick="show('ajaxrequest.php?action=removefield','div1');show('ajaxrequest.php?action=reloaddiv2','div2')">verwijderen</a> While both seperate actions work they dont when I put them together. Anyone know how to fix this ? My ajax.js with funcition...
4
2526
by: UKuser | last post by:
Hi, I'm working on the following code, which works fine in Firefox, but not in IE. The problem is its not posting the variable to my page and I'm thinking its something wrong with the getElementByID but the code is as per an example on a tutorial website (http://www.tizag.com/ ajaxTutorial/ajax-javascript.php). The Select element is as...
0
7178
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one...
2
3144
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand...
3
3941
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards the bottom of the onComplete function, there is a call to doGetAddressContacts(), which accepts an address ID. This then returns a list of contacts...
7
3550
by: RaefKandeel | last post by:
Hi all, this is my first post. I have a little ajax assignment that works fine on mozilla firefox 2.0, but doesn't work at all on Internet Explorer 7. Apparently it has to do with the line where tempDiv element takes the value from xhr.responseText. The line that says: tempDiv.innerHTML= xhr.responseText;. Apparently Internet Explorer 7 cuts...
22
1681
by: sheldonlg | last post by:
I am looking for a clean solution to a problem that I solved in, what I call, a "dirty" way. Here is what I want to do. I have a dropdown list. Clicking on an item in the dropdown list invokes an AJAX call that gets data which populates the entire lower part of my screen. It does this with an innerHTML for the div tag that holds all of...
6
5394
by: rayliu | last post by:
Recently, I have been attempting to pick up AJAX and discovered a slight problem with innerHTML.. I have <div id='container'></div> then ..
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.