Solved

Returning and executing javascript with AJAX

Posted on 2011-03-16
2
286 Views
Last Modified: 2012-05-11

Hi there,

I am using AJAX on my current website project to update my pages dynamically.  

I am having a problem when I return a script for execution on the page.  When I receive the ajax return, my callback function simply puts it into a hidden div using jquery's html() call.  

This parses the script and it runs.  So if I include a script in there it gets run.

However, I would like to also be able to call scripts that exist on the current page (not in the ajax return)

I have seen talk of using namespaces .. but I do not know how to frame this up.

Can anyone help me?

The attached is my sample code process.  When AJAX places the script in my hidden worker div via .html() it executes the returned function properly, but the call to the function in the current page does not ... and no error is thrown.

ON MY PAGE:

--> This is the script which retrieves with AJAX:

function Grab_Script(parm1,parm2)
	{
		
		Proxy.callMethod('grab_script', [parm1,parm2], function(result){
		
		$("#worker_div").html(result);
				
			},onPageError);			
					
	}

-->This is the sample function that already exists on the page:

	
	function page_func()
	{
	alert('this function already exists on the page');
	}


-->  This is what the ajax return looks like.  

<script>			
function do_this_new_func(msg)
{
	alert(msg);
}

do_this_new_func("received: call=grab_script | parm1= test | parm2= one");
do_page_func();
	
</script>

The call do_this_new_func() works.
The call do_page_func() does NOT work.

I assume that this is because it cannot access what is on the page.

So, how can I change this process so that scripts I build on the server and return via ajax can run and access other scripts/function already on the page?

Open in new window

0
Comment
Question by:srbarker8
2 Comments
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
ID: 35149885
I dont see any function with name "do_page_func();" but there is "page_func();"
0
 

Author Closing Comment

by:srbarker8
ID: 35150018
Cr@p! LOL!

It seems my formula is bad:

Low sleep + zero coffee = bleary eyed coder

Thx for the assist!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide Table in merge 3 34
How to check if a session is disconnected in php 9 32
How to control cache of some js files ? 7 44
Understanding UserAgent String 2 18
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 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