?
Solved

Ajax call a page include javascript

Posted on 2009-06-30
2
Medium Priority
?
413 Views
Last Modified: 2012-05-07
I want to use ajax to call a page, which includes javascript.
In the code below, I use ajax to call search.html and display result in div1.
In search.html, I want to run a javascript code. It seems that it doesn't work.
<form name="search">
<input name="question"  type="text" onkeyup='JavaScript:sendRequest("/search.html?q="+this.value,"div1")'>
</form>
 
<div id="div1">
Display result here.
</div>
 
 
in search.html I want to run the test javascript code:
 
<script type="text/javascript">
document.write("This is my first JavaScript!");
</script>

Open in new window

0
Comment
Question by:rxzang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
lee_mulholland earned 2000 total points
ID: 24743210
Hi,

I've also needed to do something similar in the past, and ended up replacing your div which would hold the search.html page content with an iframe, this would allow any javascript to be called and displayed to the user, otherwise only the text of the page would be displayed.

From memory the code below replicates what I used, i'd look into these examples too:

http://www.xul.fr/ajax/responseHTML-attribute.html
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Default.aspx

Thanks

Lee
<html>
 
<head>
<script type="text/javascript">
function Button1_onclick() {
	var val = "http://www.google.co.uk/search?source=ig&hl=en&rlz=&q=" + document.all.txtWebSite.value;
	document.all.myFrame.src=val;
}
</script>
 
</head>
 
<body>
 
<form id="form1">
	Search:<input id="txtWebSite" name="txtWebSite" type="text" value="Test">
	<input id="Button1" name="Button1" onclick="return Button1_onclick()" type="button" value="Show">
</form>
 
<iframe id="myFrame" frameborder="0" width="100%" height="200px"></iframe>
 
</body>
 
</html>

Open in new window

0
 

Author Comment

by:rxzang
ID: 24746320
Thanks. But I don't like frame that much. Is there other simple example that can realize this with div? Thanks a lot!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello World !, Thanks : My Sincere thanks to @Michael Male who encouraged me to write an article on this in my  blog (http://scribblejava.wordpress.com). Introduction:       There are several technical issues a developer may face in his…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question