ajax call / javascript response / render partial

Hello,

I added a simple ajax link inside a view. This does nothing but invoke an action that in turn renders, through partial render a page with a simple javascript alert.

I set the fourth parameter of partial rendering to true to indicate that it should process the result.

The ajax call is successful but the Javascript code is not interpreted.

Why?

thanks

Hi Ciro,

I had a similar problem a while back. I never really came to a firm reason as to why it was happening, I think that jQuery was stripping the script tags from what it was inserting… My solution was to return the HTML and Javascript as parts of a JSON object and process them independently, which I chose as it allowed me to update multiple parts of the page with a single AJAX request, but that might not be everyone’s cup of tea.

I’d use some form of dev tools to figure-out if the JavaScript is actually being included. If it is, I’d next look at where it is in the code. Firebug’s Net tab, if open, will show you the transfers and can be used to inspect the content of AJAX responses, the network tab in Chrome’s Developer Tools has much the same purpose.

Note that, if it’s in the $(document).ready(), remember that this function won’t be called by default as the document was ready ages ago, and you may not want to call it again as you may end-up doubling-up event handlers of what is already on the page.

Was that any help?

thanks for reply but this solution can’t work in my case

the result of render is:




<script>

alert(testo);

</script>




i saw it with chrome tools

I just do not run

I can do?

You should place the response in the page at the on success.

Also the you should use alert("testo") (con le virgolette)

Hello Zaccaria,

I’m sorry if I reply late, but the code was present on the machine

office and I could not try. I followed your directions and everything

working properly. Why you need to work this way? I thought

that option update is similar to succes.

Hello and thank you again.

Ciro

Hello Zaccaria,

I’m sorry if I reply late, but the code was present on the machine

office and I could not try. I followed your directions and everything

working properly. Why you need to work this way? I thought

that option update is similar to succes.

Hello and thank you again.

Ciro