• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 295
  • Last Modified:

Returning and executing javascript with AJAX

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.


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

function Grab_Script(parm1,parm2)
		Proxy.callMethod('grab_script', [parm1,parm2], function(result){

-->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.  

function do_this_new_func(msg)

do_this_new_func("received: call=grab_script | parm1= test | parm2= one");

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

1 Solution
HainKurtSr. System AnalystCommented:
I dont see any function with name "do_page_func();" but there is "page_func();"
srbarker8Author Commented:
Cr@p! LOL!

It seems my formula is bad:

Low sleep + zero coffee = bleary eyed coder

Thx for the assist!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now