Blog

Mar
17

Ajax.Updater and javascript

Posted by Michael Cindric in javascript, ruby on rails | 2 Comments »

Ran into a little problem today which made me think for a second. I have a Javascript function that runs once a calendar control is closed. It just passes a parameter to a action which renders a view nothing fancy.

So my onClose function looks like so

function onClose(cal) {
	var p = cal.params;
	new Ajax.Updater('overlapping', '/visits/new', {
	  parameters: { start_date:  p.inputField.value; },
	  evalScripts: true
	});
	cal.hide();
};

This will fire once the calendar is closed. ‘Overlapping’ is the ID of the Div ill be updating and ‘/visits/new’ is the path of the action in your controller. This will then pass the start date param to the action which can then be used in the view. The problem l had is that l had some javascript on the partial that was not executing. Had to think for a minute and then it turned out that evalScripts is false by default thus the javascript was not executing.

So its as simple as having the following as a param in your Ajax.updater

 evalScripts: true

Once you have done that your good to go.

2 Responses

03.17.09

Actually it seems that I have a similar problem but I don’t know if tbe cculprit has something to do with the eval thing haven’t tested it yet. It’s been boggling my mind up to now. My Ajax.Updater statements are erratic. Sometimes they execute, but when I reupload the same files into the server (no code modifications) they do not execute. I don’t know the reason. I hosted my site on on e of the free hosting sites. After I reupload the files those Ajax.Updaters do not execute, after several minutes when I opened the pages again in the browser, they execute. Recently I got a new host and reuploaded the same website files after which I tested it and they do not execute! I was looking for s solution to this on Google till I found this page.

03.17.09

Test it out and let me know if l can do anything more to help

Leave Your Response

Name*
Email*
Website URL
Comments*
* Name, Email, Comment are Required
*

Spam Protection by WP-SpamFree