winter winter - 1 year ago 83
jQuery Question

after append content and invoke function in jquery

there are data page:_data.cshtml

<table id="example1" class="display table table-bordered">
<th>Start date</th>
<a href="#" url="/data/index" save-data="default"> Save Changes </a>

there are container page

<div class=".mycontainer"></div>

when i load data in container page like this:

$('.mycontainer').append(data).on('click', '[save-data="default"]', function (event) {

function load(event) {
var url = $(this).data("url");

url == undefined

i hope the value url = "/data/index"

i can append the partial page(

but i can not get the value.

please give me some point ,thanks!

Answer Source

Try changing to

$('.mycontainer').append(data).on('click', '[save-data="default"]', load);

Now without the anonymous function the arguments and this context will be correct

Also seems to be a typo in class name in html that shouldn't have a dot in it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download