Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,


I have a issue with using my bundle scripts inside a div.
I have inside my main layout some scripts one of those is:

@Scripts.Render("~/bundles/menus")


Inside the layout I have a div without html content:

<div id="ajaxResponse" ActieID="0" relatieID="0"></div>


I fill this content with a ajax post.


$("#action").click(function () {
     var id = $('#ajaxResponse').attr('data');
     $.ajax(
         {
             type: 'POST',
             dataType: 'html',
             url: 'Menus/action',
             success: function (result) {
                 $('#ajaxResponse').html(result);
             },
             error: function (error) {
                 alert('Fail');
             }
         });
 });


This post will return a partial view which will be inside the AjaxResponse div. Now I have the issue that none of the scripts able to use inside this partial view. Because I render the content of the div after layout and script bundles.

Ofcorse I can set the partialView to a normal View to solve this problem(rendering evrything) but I don't want that much content inside this div.

Does anyone know a way to render this scripts from the layout after a ajax post?
already tryed to use $(document).ready and $("action").on("click" function()) and kind of tricks. But it didn't work because the scripts not usable inside this div.

I tryed also a click event on this

Like:

$('#ajaxResponse').on("click", function()) {
//my click event
}


This was working but ended up ofcorse in a double click action.

I hope someone of you guys know the right way to solve this!
Posted

1 solution

Hi Wessel,

If you are using jquery 2.1.4, then you should try like this.
$(document).on('click','#action',function(){

});

or if you are using below version then like this :
$('#action').live('click',function(){

});

these both are works with that content as renders after the layout.
you can try once like this.

not sure in your situation but working fine with me
 
Share this answer
 
Comments
Wessel Beulink 5-Nov-15 7:47am    
Yeah, I tryed this function for some parts this work. Already found out to just render the script inside the current partial view which will include the thing I need. But the problem here is that I don't have any controll over the .js file this is a public one. And I don't want to render in every pop-up-modal a .js scripts section. thats what i'm trying to avoid.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900