javascript - Ajax not loading -


I'm dynamically adding an option to a drop down list with AJAX jquery and PHP but for some reason It is not working. Please check your code:

AJAX

  $ ("# Course"). Change (function () {var id = $ (this) .val (); $ .XX ({type: "post", url: "..//.jject.php"), data: id, cache: incorrect, Success: function (html) {$ ("# sub"). Html (html);}});});  

ajax-select.php

  & lt ;? Php if ($ _ POST ['id']) {$ id = $ _ post ['id']; $ Sql ​​= mysql_query ("SELECT * FROM` topics WHERE 'course_id` =' $ id '"); While ($ line = mysql_fetch_array ($ sql)) {$ id = $ row ['sub_id']; $ Data = $ line ['sub_name']; Echo '& lt; Option value = "'. $ Id.'" 'Gt;' $ Data '& Lt; / Option & gt; '; }}? & Gt;  

HTML

  & lt; Select class = "form-control" name = "course" id = "course" & gt; & Lt; Option value = "no select" & gt; Choose Course & lt; / Option & gt; & Lt ;? Select_course () ;? & Gt; & Lt; / Select & gt; & Lt; / Div & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Div class = "input-group" & gt; & Lt; Span class = "input-group-addon" & gt; Subject & lt; / Span & gt; & Lt; Select class = "form-control" name = "sub" id = "sub" & gt; & Lt; Option value = "No selection" option selected & gt; Select topic & lt; / Option & gt; & Lt; / Select & gt; & Lt; Script src = "// ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> & Lt; Script src = "js / app.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Additional information:

  • The ID assigned to the selected options is correct
  • Ajax code is in another folder in the folder named JS

Why am I going wrong?

Change the Div class = "post-text" itemprop = "text">

:

If your content is dynamically generated (added after the DOM is ready), then use the following:

Id: id =,

  $ (document) .on ('change', '#course', function () {// your code here} );  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -