473,773 Members | 2,277 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 3849
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
1892
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 the context of that code, which is the AJAX function that is called when a radio button is clicked,...
17
11883
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 show
4
2546
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 follows: <select style="width:240px;font-size:8pt" id='servicet'
0
7191
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 page basically. So how can a person deep link to something that is on one page? This question...
2
3173
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 whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
3
3955
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 at that address. What I am trying to do is for each address that it retrieves and outputs, as it...
7
3558
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 off some tags. There goes my code:- HTML:- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
22
1695
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 this. This works fine. I also have an "Edit" button that I want to show next to dropdown list,...
6
5397
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
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10039
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
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
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.