473,379 Members | 1,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Getting error object does not support this property or method

I am using Ajax with struts in web application.

from jsp i am calling a function of ajax.js onclick of a button.
code of that call function which calling from jsp given as below:-
onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHo meForm')"

after clicking on button i am getting following error:-

object does not support this property or method
at statement (Which i have made it bold in js file)

[i]content=newTextElements.substring(startContentPos)

if any one has solution plz help me.
thanks in advance..

contain of Ajax.js file

//global variables
var req;
var which;


/**
* Get the contents of the URL via an Ajax call
* url - to get content from (e.g. /struts-ajax/sampleajax.do?ask=COMMAND_NAME_1)
* nodeToOverWrite - when callback is made
* nameOfFormToPost - which form values will be posted up to the server as part
* of the request (can be null)
*/
function retrieveURL(url,nameOfFormToPost) {

//get the (form based) params to push up as part of the get request
url=url+getFormAsString(nameOfFormToPost);

//Do the Ajax call
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true); //was get
} catch (e) {
alert("Problem Communicating with Server\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE

req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}
}

/*
* Set as the callback method for when XmlHttpRequest State Changes
* used by retrieveUrl
*/
function processStateChange() {

if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response

///alert("Ajax response:"+req.responseText);

//Split the text response into Span elements
spanElements = splitTextIntoSpan(req.responseText);

//Use these span elements to update the page
replaceExistingWithNewHtml(spanElements);

} else {
alert("Problem with server response:\n " + req.statusText);
}
}
}

/**
* gets the contents of the form as a URL encoded String
* suitable for appending to a url
* @param formName to encode
* @return string with encoded form values , beings with &
*/
function getFormAsString(formName){

//Setup the return String
returnString ="";

//Get the form values
formElements=document.forms[formName].elements;

//loop through the array , building up the url
//in the form /strutsaction.do&name=value

for ( var i=formElements.length-1; i>=0; --i ){
//we escape (encode) each value
returnString=returnString+"&"+escape(formElements[i].name)+"="+escape(formElements[i].value);
}

//return the values
return returnString;
}

/**
* Splits the text into <span> elements
* @param the text to be parsed
* @return array of <span> elements - this array can contain nulls
*/
function splitTextIntoSpan(textToSplit){

//Split the document
returnElements=textToSplit.split("</span>")

//Process each of the elements
for ( var i=returnElements.length-1; i>=0; --i ){

//Remove everything before the 1st span
spanPos = returnElements[i].indexOf("<span");

//if we find a match , take out everything before the span
if(spanPos>0){
subString=returnElements[i].substring(spanPos);
returnElements[i]=subString;

}
}

return returnElements;
}

/*
* Replace html elements in the existing (ie viewable document)
* with new elements (from the ajax requested document)
* WHERE they have the same name AND are <span> elements
* @param newTextElements (output of splitTextIntoSpan)
* in the format <span id=name>texttoupdate
*/
function replaceExistingWithNewHtml(newTextElements){

//loop through newTextElements
for ( var i=newTextElements.length-1; i>=0; --i ){

//check that this begins with <span
if(newTextElements[i].indexOf("<span")>-1){

//get the name - between the 1st and 2nd quote mark
startNamePos=newTextElements[i].indexOf('"')+1;
endNamePos=newTextElements[i].indexOf('"',startNamePos);
name=newTextElements[i].substring(startNamePos,endNamePos);

//get the content - everything after the first > mark
startContentPos=newTextElements[i].indexOf('>')+1;
content=newTextElements[i].substring(startContentPos);

//Now update the existing Document with this element

//check that this element exists in the document
if(document.getElementById(name)){

//alert("Replacing Element:"+name);
document.getElementById(name).innerHTML = content;
} else {
//alert("Element:"+name+"not found in existing document");
}
}
}
}
Sep 15 '06 #1
1 9462
rpjd
25
I am using Ajax with struts in web application.

from jsp i am calling a function of ajax.js onclick of a button.
code of that call function which calling from jsp given as below:-
onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHo meForm')"

after clicking on button i am getting following error:-

object does not support this property or method
at statement (Which i have made it bold in js file)

[i]content=newTextElements.substring(startContentPos)

if any one has solution plz help me.
thanks in advance..

contain of Ajax.js file

//global variables
var req;
var which;


/**
* Get the contents of the URL via an Ajax call
* url - to get content from (e.g. /struts-ajax/sampleajax.do?ask=COMMAND_NAME_1)
* nodeToOverWrite - when callback is made
* nameOfFormToPost - which form values will be posted up to the server as part
* of the request (can be null)
*/
function retrieveURL(url,nameOfFormToPost) {

//get the (form based) params to push up as part of the get request
url=url+getFormAsString(nameOfFormToPost);

//Do the Ajax call
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true); //was get
} catch (e) {
alert("Problem Communicating with Server\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE

req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
req.send();
}
}
}

/*
* Set as the callback method for when XmlHttpRequest State Changes
* used by retrieveUrl
*/
function processStateChange() {

if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response

///alert("Ajax response:"+req.responseText);

//Split the text response into Span elements
spanElements = splitTextIntoSpan(req.responseText);

//Use these span elements to update the page
replaceExistingWithNewHtml(spanElements);

} else {
alert("Problem with server response:\n " + req.statusText);
}
}
}

/**
* gets the contents of the form as a URL encoded String
* suitable for appending to a url
* @param formName to encode
* @return string with encoded form values , beings with &
*/
function getFormAsString(formName){

//Setup the return String
returnString ="";

//Get the form values
formElements=document.forms[formName].elements;

//loop through the array , building up the url
//in the form /strutsaction.do&name=value

for ( var i=formElements.length-1; i>=0; --i ){
//we escape (encode) each value
returnString=returnString+"&"+escape(formElements[i].name)+"="+escape(formElements[i].value);
}

//return the values
return returnString;
}

/**
* Splits the text into <span> elements
* @param the text to be parsed
* @return array of <span> elements - this array can contain nulls
*/
function splitTextIntoSpan(textToSplit){

//Split the document
returnElements=textToSplit.split("</span>")

//Process each of the elements
for ( var i=returnElements.length-1; i>=0; --i ){

//Remove everything before the 1st span
spanPos = returnElements[i].indexOf("<span");

//if we find a match , take out everything before the span
if(spanPos>0){
subString=returnElements[i].substring(spanPos);
returnElements[i]=subString;

}
}

return returnElements;
}

/*
* Replace html elements in the existing (ie viewable document)
* with new elements (from the ajax requested document)
* WHERE they have the same name AND are <span> elements
* @param newTextElements (output of splitTextIntoSpan)
* in the format <span id=name>texttoupdate
*/
function replaceExistingWithNewHtml(newTextElements){

//loop through newTextElements
for ( var i=newTextElements.length-1; i>=0; --i ){

//check that this begins with <span
if(newTextElements[i].indexOf("<span")>-1){

//get the name - between the 1st and 2nd quote mark
startNamePos=newTextElements[i].indexOf('"')+1;
endNamePos=newTextElements[i].indexOf('"',startNamePos);
name=newTextElements[i].substring(startNamePos,endNamePos);

//get the content - everything after the first > mark
startContentPos=newTextElements[i].indexOf('>')+1;
content=newTextElements[i].substring(startContentPos);

//Now update the existing Document with this element

//check that this element exists in the document
if(document.getElementById(name)){

//alert("Replacing Element:"+name);
document.getElementById(name).innerHTML = content;
} else {
//alert("Element:"+name+"not found in existing document");
}
}
}
}
I have used ajax to execute a php script to query a database. I have viewed the results with an alert confirming the scipt executed. When I tried to get the individual elements from the responseText using getElementById and getElementByName, but I have got "object does not support this property or method" with both. Can anyone tell me why this error is occuring?
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2.     function displayParts()
  3.     {
  4.     var fieldname = new Array();
  5.     var parts = new Array();
  6.     var numfields;
  7.     var numrows;
  8.     document.write('<tr>');
  9.     for (j=0; j < numfields; j++)
  10.         {
  11.         document.write('<td><span id="fieldname[j]"></td>');
  12.         }
  13.     document.write('<\/tr>');
  14.     for (i=0; i < numrows; i++)
  15.         {
  16.         document.write('<tr>');
  17.         for (j=0; j < numfields; j++)
  18.             {
  19.             document.write('<td><span id="parts[i][j]" /></td>');
  20.             }
  21.             document.write('</tr>');
  22.         }
  23.     }
  24.     </script>
  25.  
Apr 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: news.onetel.net.uk | last post by:
I and my friend Karl have spent literally all day trying to find out what is causing my error but we are zapped of any further functionality :) I have a form that adds news records. You select...
21
by: Michael Bierman | last post by:
Please forgive the simplicy of this question. I have the following code which attempts to determine the color of some text and set other text to match that color. It works fine in Firefox, but does...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
32
by: paul | last post by:
HI! I keep on getting this error and I have tried different things but I am not sure how to send the expiring date. The error that I am getting in Firefox 1.5 is "Error: expires.toGMTString is...
4
by: Cylix | last post by:
Sample code of the problem: function inputOne() { alert('a'); } <input name="inputOne" id="inputOne" value="Warn" onclick="inputOne()"> The error is the object doesn't support this method.
5
by: John Olbert | last post by:
Subject: Error is Object doesn't support this property or method I am trying to pass a C# string under Vs2005 (Net2) to an Vb6 ActiveX Control. I get the following runtime error-- "Object...
8
by: Kevin Blount | last post by:
I'm tyring to access an object created by using a method from a third party API. The documentation tells me what object should be return, and the properties of that object, but when I try and...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.