php - why after click on tag , page refresh and not work appendTo? -



php - why after click on tag <a>, page refresh and not work appendTo? -

tag a $.each(). see js code:

$('.auto_complete').keyup(function () { var id = '#' + this.id; var alt = $(id).attr('alt'); var id = $(this).attr('id'); var name = $(this).attr('name'); var url = alt + id + '/' + name; var dataobj = $(this).closest('form').serialize(); $.ajax({ type: "post", url: url, data: dataobj, cache: false, datatype: 'json', success: function (data) { $(".list_name").show().html(''); $.each(data.name, function(a,b){ $(".list_name").append('<p><a href="" id="result">' + b + '</a></p>'); ////////////////////here///////////////////// $('.list_name p a').live('click', function(e) { e.preventdefault(); $('<b>' + b + '، </b><input type="text" name="hotel[]" value="' + b + '" style="border: none; display: none;" />').appendto('.auto_box span'); $(this).remove(); homecoming false; }); ///////////////////////////////////////////// }); if($('.auto_complete').val()==''){ $(".list_name p").hide().remove() } $('body').click(function(){ $(".list_name p").hide().remove(); $('.auto_complete').val(''); }); }, "error": function (x, y, z) { // callback run if error occurs alert("an error has occured:\n" + x + "\n" + y + "\n" + z); } }); });

php:(i utilize of codeigniter)

function search_hotel(){ $search_term = $this->input->post('search_hotel'); $query = $this->db->order_by("id", "desc")->like('name', $search_term)->get('hotel_submits'); $data = array(); foreach ($query->result() $row) { $data[] = $row->name; } echo json_encode(array('name' => $data)); // echo: {"name":["333333","\u0633\u0644","\u0633\u0644\u0627\u0633\u06cc","\u0633\u0644\u0627\u0633\u0633","\u0633\u0644\u0627\u0645"]} }

how approach solution might depend on whatever else have attached link in terms of events. seek instead:

$('.list_name p a').live('click', function() { $('<b>' + b + '، </b><input type="text" name="hotel[]" value="' + b + '" />').appendto('.auto_box span'); $('.list_name p a').remove(); homecoming false; });

i created jsfiddle example, seems working fine. if you're still getting form submission there might other syntax errors in code or other events tied elements interfering or preventing desired behavior occurring.

php javascript jquery codeigniter

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -