Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning javascript from an ajax call

Status
Not open for further replies.

WebRic

Technical User
Sep 21, 2004
95
0
0
GB
Hi,

I've a page the use AJAX to call up some HTML. There is a fair amount of HTML so I break into 50 character per line using server side code and the present it back. I escape the speech marks using \. However, I have some inline javascript and some functions which I think is messing up the returned code. I've listed the code that should get returned to the page. But I hit a javascript error which prevents the page from getting updated

Any advice would really help.
Thanks,

Richard
Code:
			var thetable = " "






	
		 
			thetable += "<table class=\"admintable\"><thead>  <tr>    <th c"
			
		
	
		 
			thetable += "lass=\"iconcell\">Ref</th>    <th>Description</th>"
			
		
	
		 
			thetable += "    <th class=\"iconcell\">Date</th>    <th class="
			
		
	
		 
			thetable += "\"iconcell\">Decision</th> <th class=\"iconcell\">"
			
		
	
		 
			thetable += "Edit</th> <th class=\"iconcell\">Delete</th>  </tr"
			
		
	
		 
			thetable += "></thead>    <tr class=\"oddrow\" onMouseOver=\"th"
			
		
	
		 
			thetable += "is.className='highlightrow'\" onMouseOut=\"this.cl"
			
		
	
		 
			thetable += "assName='oddrow'\">    <td>ref test</td>    <td>de"
			
		
	
		 
			thetable += "sc test</td>    <td>date test</td>    <td>decision"
			
		
	
		 
			thetable += " test</td> <td>edit</td> <td>Delete</td>  </tr> <t"
			
		
	
		 
			thetable += "r>    <td><input type=\"text\" name=\"ref\" id=\"r"
			
		
	
		 
			thetable += "efph\" class=\"inputbox\" /></td>    <td><input ty"
			
		
	
		 
			thetable += "pe=\"text\" name=\"description\" id=\"descriptionp"
			
		
	
		 
			thetable += "h\" class=\"inputbox\" /></td>    <td><input type="
			
		
	
		 
			thetable += "\"text\" name=\"itemdate\" id=\"itemdateph\" class"
			
		
	
		 
			thetable += "=\"inputbox\" /></td>    <td><input type=\"text\" "
			
		
	
		 
			thetable += "name=\"decision\" id=\"decisionph\" class=\"inputb"
			
		
	
		 
			thetable += "ox\" /></td>    <td colspan=\"2\" align=\"center\""
			
		
	
		 
			thetable += "> <input type=\"button\" name=\"submit\" id=\"subm"
			
		
	
		 
			thetable += "itph\" value=\"Add Entry\" onClick=\"addPH(); retu"
			
		
	
		 
			thetable += "rn false;\" /> </td> </tr></table>"
			
		
	
document.getElementById('tableph').innerHTML = thetable;


 
You say "should"... does it? Use Firefox and install the Firebug extension - then you can see the response for XMLHTTP Requests. This is an essential tool when you start trying to debug your javascript (especially AJAX) code.

Your problem all comes down to how the code on your page (the one that is initialing and managing the AJAX call) is written to manage the returned request.

I'm picking you haven't quite got the logic of how AJAX works right yet. Get rid of all the theTable+= stuff... just return the ACTUAL table as you would see it when you code it. This will be made available via the XMLHTTP Request object - and it is in this section of the code that you would set the innerHTML of the "tableph" node to the returned result.

Are you using a framework like Prototype or Dojo to do this? Show us your code and we can probably straighten it out a little.

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Since the OP isn't here to say... I'm gonna suggest it's a DIV element. Maybe it's a P element... actually... it's possibly a SPAN - validation be damned [smile]

Any other questions you'd like me to answer on behalf of WebRic, lemme know!

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Damn that validation!!!

Any other questions you'd like me to answer on behalf of WebRic, lemme know!

WebRic, BabyJeffy, will you give me all of your money?? (Remember, you are answering for WebRic)


[monkey][snake] <.
 
hi all,

thanks for the repsonses. I'm using an old version of SACK for the AJAX. I've managed to find more problems & solutions. I've now seem to have it working but with a delay. I.e. an onclick event to initiate the AJAX call won't display until a subsequent onclick event is fired.

It's really wierd but I'll dig further and let you know if I find the solution. I reckon it will be to do with my initial function code.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top