Friday, 15 January 2010

Using Javascript In Dynamically Embeded HTML? -


How do you use javascript in dynamically embedded pages / content or do it correctly?

Event occurring I am loading a PHP / HTML page in an HTML element. I works fine on the JavaScript output page, or the page that loads into content, but it does not work on that page Which is loading.

Here is my request job:

  function sendServiceRequest (file, nvpSendData, success callback, failed callback) {$. AZ ({type: "post", url: file, data: nvpSendData, dataType: 'html'}) Success (work, data, position) {console.log (".done"); console.log ("AJAX status Return: "+ status"; //console.log ("Success data:" + JSON.stringify (data)); Success callback (data, status);} unsuccessful (function (data, status, error) {console .log (".failed"); console.log ("Return AJAX status:" + status), //console.log ((return data: "+ JSON.Stringify (data)); Failed callback (data, status) , Error);})}}  

Then I have a php page, viewScripts.php , in which it contains Java The script file, which handles the loading process

view_events .js

  document.addEventListener ('DOMContentLoaded', function () {var rx = document.query selector "# Rx-number"). Value; sendServiceRequest ("/comments/get_content.php", {Action: "loadcontent", loadType: "comments", rx_number: rx}, function (data, position) {document.query selector ("# Rx-comments-container"). InnerHTML = data;}, function (data, status, error) {console.log ("Ajax service request failed while loading comments!");})}} ;  

In the above, the /comments/get_content.php data is being sent, and then loads the page comment. Php In a Div element, # rx-comments-container Everything is fine till this point. It has javascript in comment.php that does not work; I have to include an '.js' file with the specified task to handle events in comment.php Have tried, but it does not work I have tried to include the event function as listed above in view_events.js , which in viewScripts.php Is included, and I do not want to work either in javascript directly comments.php Javascript joining comments.php is here:

  document.addEventListener ('DOMContentLoaded' , Function () {AddEventListener ("click", function () {var id = this.value; sendServiceRequest ("/comments/get_content.php", {action: "loadContent", "edit" LoadType: "edit comment" , Comment_id: id}, function (data, position) {document.querySelector ('#' + id) .innerHTML = data;}, function (data, status, error) {console.log ("while loading AJAX edit form Service request failed! "};});}); Document.Get Elementsby-classname (" comment-history-glyph "). AddEventListener (" click ", function () {var id = this.value; sendServiceRequest (" / comments / get_content .php ", {Action:" Load Communication ", Load Type:" View History ", Comment_ID: ID}, Function (Data, Position) {document.querySelector ('# comment-body'). InnerHTML = data;}, function Data, status, error) {console.log ("Failed to load while editing the AJAX Send Service Request!");});});});  
< P>

I pay this I have been successful in putting that I think I was doing something wrong because my code was ending. I used to use only one onclick event with the sendServiceRequest function, and it was finished. There was no need to include I


No comments:

Post a Comment