php - Executing javascript in an an AJAX response - Codeigniter -


I am using Codigniter to redo a website. I have the following control code:

  public function get_topics () {$ subject = $ this- & gt; Input-> Post ('input_data'); $ Themes = $ this- & gt; Firstcoast_model- & gt; Get_topics_like (theme $); Foreign currency (subject $ $ as Wax) {resonant "and" pre-id = \ "pre_". $ Val ['id'] "\" & Gt; "; Resonance $ val ['formula']; echo" & lt; Generate a unique Javascript file. $ F = "file_" $ Val ['id'] ".js"; if (! File_exists ($ f)); {$ File = fopen ($ F, "w"); $ Js = "\ $ (\" # button_ "$ val ['id']. \"). Click (function () {\ $ (\ "# pre_". $ Val [ 'Id']. "\"). Hide ();}); "; Fwrite ($ file, $ js); Fclose ($ file); } Echo "& lt; script src = \" file_ ". $ Val ['id']." .js \ "& gt; & lt; / script & gt;"; Echo "& lt; button id = \" button_ ". $ Val ['id']." \ "Hide & lt; / button & gt;"; Echo "& lt; / pre & gt;"; }}  

The original idea to call an AJAX function to retrieve a list of sources. Javascript aims to get any formula & lt; pre > & lt; JS file (i.e. File_1.js) I can hide by hiding it from / pre > tag. I look like this:

  $ ("# button_1"). Click (function () {$ ("# pre_1"). Hide ();});  

And the button code is:

  & lt; Button ID = "button_1" & gt; Hide & lt; / Button & gt;  

The problem is that it does not work. Files are generated, but clicking on the "Hide" button does nothing, the shocking part is that the exact same code works on the original website, where I only call AJAX calls in a PHP file I am

Any ideas that may be here?

Edit:

I used on my old website:

  $ query = "Select" from the topics where the word '%' . $ Word "% '"; $ Result = mysql_query ($ query); While ($ val = mysql_fetch_array ($ result)) {resonance "and" pre-id = \ "pre_". $ Val ['id']. "\" & Gt; "; Etc ..}} And everything works fine if I now put the results of the loop in an array and after that I loop a foreshop, then the results are very intermittent I'm wondering if there is a project loop problem.   

I think you list in JSON response Can return the button

  public function get_topics () {$ subject = $ this-> input- & gt; post ('input_data'); $ topics = $ this- & gt; ; First case T_model-> get_topics_like ($ theme); $ response = array ('button' => $ subject); header ('content-type: application / js'); echo json_encode ($ arr);} < / Code> 

so that the client can parse that button element.

  & lt; script type = "text / javascript"> $ (document). ('Submit', function () {// This event fire when a som load load $ .ajax ({url: 'url to getTopics () controller'), at RDE (function () {$ ('sommel'). Type: "Post", Data: 'input_data =' + $ (this) .val (), // Depending on your input name data Change it and type: 'json', // a JSON datatype choose success: function (data) to {(data Bikti.ank In data.battons) {$ (BTN) .hide ();}}}); Return falls; // stop the page from refreshing}};}); & Lt; / Script & gt;  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -