Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Views » How to prevent renderPartial render javascript at each request
0 Votes
Vote Con!
Solved!

How to prevent renderPartial render javascript at each request

AJAXduplicatejavascriptpreventrenderPartial

sorry, I just asked this question to Yii forum, but no comment :(

I have a index, calling JUiDialog, and use ajax to call another controller action result (HTML), which will show in that dialog
this action result has button with javascript actions, so I use renderPartial in the controller action to generate the HTML

but when User let the Dialog show again and again, this controller action has been request more and more times
then my index got a lot of same javascript code blocks

it’s funny, when User click the button in the dialog, the javascript code execute a lot
so they will see 3 times same alert, or even more

how to prevent javascript code pass each request? I just want to have 1 javascript code block at the first time

By taker.wu in Views · Asked 556 days 12 hours ago

Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0

 

Answers (4)

  1. 2 votes

    This is because you don’t remove your jQuery bind/live events.
    Check http://www.yiiframework.com/wiki/216/update-delete-model-with-cjuidialog-works-in-cgridview/ and http://www.yiiframework.com/extension/eupdatedialog/ for examples how to fix this problem (yes both links are by me, and it looks like I removed the explanation about jQuery events so you will have to dig into source code), happy shoveling :)

    By IFDattic · 555 days 5 hours 41 mins ago

    Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0

  2. 1 vote
    Accepted

    RenderPartial has two extra parameters : return and process output. The process output what it does is exactly that, process/renders the javascript.

    For more advanced requirements:

    By tonydspaniard · 553 days 17 hours 25 mins ago

    Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0

    • If you have set a bind event ON THE MAIN VIEW page not on the AJAX'ed contents then it shouldn't be that problem. But live (previous to jquery 1.7) binding normally provoques those type of issues.

      By tonydspaniard · 553 days 17 hours 20 mins ago

  3. 0 votes

    thanks for ifdattic & tony, yeah I just check Yii’s ajaxButton action, it use “delegate” & “undelegate”, as I use ‘live’ but without die :p

    my fault, thx your helps!

    By taker.wu · 553 days 11 hours 48 mins ago

    Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site