Welcome Guest, Not a member yet? Register   Sign In
help, problem whit ajax.update
#1

[eluser]zyddee[/eluser]
Ive got this javascript code that i want to be executed from the controller whit help of Ajax.Updater..

Ive set the parameter evalScripts to true, but it still doesn't executes the javascript, iv also tried to tell the function that the content-type is text/javascript without success.. somebody who knows what I'm doing wrong here?

copy/pasted this from scriptaculous page:
Quote:Hint: If you have set evalScripts:true the script you call (the url parameter) must return a header of ‘Content-Type: text/javascript’ else the browser will not execute it.

my code:
Code:
new Ajax.Updater('timeChart', base_+'timeChart_controller/refresh_grid, {method: 'post', postBody:'weekno='+weekno, evalScripts:true, insertion:'Top'});

Code:
function refresh_grid()
    {
        header("Content-Type: text/javascript; charset=UTF-8");

        $data = "< script >";
        $data .= "alert('foo');"
        $data .= "</ script >";

        echo $data;            
    }
#2

[eluser]alpar[/eluser]
Can you use that header like that? i know you can use it in meta tags, but not sure that is a valid header you have there, try removing the charset=utf-8 from there. And check some documentation on headers for the exact syntax to be used
#3

[eluser]Crafter[/eluser]
The evalScripts scripts in prototype does not always work, espacially in Firefox. Firefox sometimes cleans your code nefore rendering ot.

Rather capture your output and eval() it.

Alternatively, load your scripts in your main page and execute them on update sucess. I prefer this technique.
#4

[eluser]zyddee[/eluser]
thanks for sugestion alpar and thanks for the tip Crafter.

I found a solution for my problem:
in ajax.updater it should be "insertion: Insertion.Top", not "insertion: 'Top'"




Theme © iAndrew 2016 - Forum software by © MyBB