开发者

Run javascript code returned when using Zend Frameworks ZendX ajaxLink function

I had this working an hour ago but must have changed something. How should I call a ajaxLink using ZendX so that any javascript in the response html get's executed? I tried with processData since I think I used that but now it doesn't work.

<?php echo $this->ajaxLink('Click me and I will run the returned javascript code',
                    $this->url(array('controller' => 'foo', 'action' => 'bar')),
                    array('id' => 'myi开发者_JAVA百科d'),
                                'processData' => true,
                                'method' => 'post',
                                'async' => false
                    ),
                    array('a_posted_id' => $the_posted_id));?>


This SHOULD work and is probably just a bug somewhere in the ajaxLink() code. I ended up returning JSON encoded data and having javascript functions to act on the returned data instead.


How is the response being returned?

In general in the non-zend. You can build a javascript tag via javascript .

  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.text = "the returned javascript";
  document.getElementsByTagName('head')[0].appendChild(script);

This will automatically run the code.

Or have your Ajax return a url to a file and instead of text set the src of the tag.

 var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = "/the/returned/link.js"
  document.getElementsByTagName('head')[0].appendChild(script);

In both cases the javascript will be run automatically.

Sorry if this doesn't help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜