javascript - Best practice for triggering events on calling page from an ajax page -
i have page lists bunch of files. page can accessed directly via url or can loaded in modal dialog via ajax different page.
if files page loaded via ajax, allow user click name of file , trigger action in page loaded files page. example, there article edit page. page contains "attach file" button. when user clicks button, files page loaded in modal dialog , when filename clicked, id of file inserted article form , dialog closed. there event edit page similar button, handle filename-click event differently on page.
i'd handle these click events differently depending on calling page. @ moment i'm defining handler function global scope in page containing form files being attached, testing function in the files-page when filename clicked , calling if exists. works feels little hacky. there kind of best practice sort of thing i'm not aware of?
i'm using jquery if makes things easier in way..
you should @ jquery live
attach handler event elements match current selector, , in future.
when ajax page loaded it's not processed dom in same way main page loaded, therefore using live attach event on current event emitters future ones such dynamic ajax content
within ajax model
<div> ... <a href="#" id="ajax_click_event">add main page</a> ... </div> and within static page (the 1 loaded)
$("#ajax_click_event").live('click',function(){ //work wit value of form within ajax div. })
Comments
Post a Comment