Welcome Guest, Not a member yet? Register   Sign In
why multiple times ajax call can fire when using autocomplete in codeigniter
#1

[eluser]Unknown[/eluser]
hi...
i have implement the radiobutton with autocomplete using ajax..
but problem is that ajax can call multiple times...
i have use mvc pattern as well as js file...
plz help..
thanks in advance..



Here is my controller....

function autocomplete_certificate($related)
{
$value = strtolower($this->input->post('q',TRUE));
$resutl = '';
//echo $related;
if($related == 0)
{
echo "hiiiii";
$items = $this->model_opportunity->autocompletecertificate($value);
echo "[";
foreach ($items as $item) {
echo "{ name: \"$item->first_name\", to: \"$item->contact_id\" }, ";
}
echo "]";
}

else
{
echo "hello";
$items = $this->model_opportunity->autocomplete_party($value);
echo "[";
foreach ($items as $item) {
echo "{ name: \"$item->party_name\", to: \"$item->party_id\" }, ";
}
echo "]";
}

}

Here is my model....

/*===================================================================================================
* Function Name:- autocompletecertificate()
* Description : Get Factory name from the tbl_opportunity_master
*====================================================================================================
*/
function autocompletecertificate($value)
{
$this->db->select('contact_id,first_name');
$this->db->from('tbl_contact_master');
$this->db->like('first_name',$value);
$this->db->where('tbl_contact_master.is_active',0);
$this->db->where('tbl_contact_master.is_delete',0);
$query = $this->db->get();
$data = $query->result();
return $data;
}
/*===================================================================================================
* Function Name:- autocomplete_party()
* Description : Get Factory name from the tbl_opportunity_master
*====================================================================================================
*/
function autocomplete_party($value)
{
$this->db->select('party_id,party_name');
$this->db->from('tbl_party_master');
$this->db->like('party_name',$value);
$this->db->where('tbl_party_master.is_active',0);
$this->db->where('tbl_party_master.is_delete',0);
$query = $this->db->get();
$data = $query->result();
return $data;
}


Here is my view....

<td><label>Related To: </label></td>

<td><select id="active_opportunity" name="active_opportunity">

<option value="0" >Contact </option>
<option value="1" >Party</option>
</select>
</td>


here is my js file.....


function show_add_opportunity_dialog(value)
{
dijit.byId('dialogAddopportunity').show();
//seturl();
userautocomplete();
}
function seturl(value)
{
alert(value);

var related = $("#offer").val();

//alert(related);
var url = sitepath+'opportunity/autocomplete_certificate/' +value;
$(function() {
function format(mail) {
return mail.name + " (" + mail.to + ")";
}
$("#txtcontactid").autocomplete(url,
{
multiple: false,
parse: function(data) {
return $.map(eval(data), function(row) {

return {
data: row,
value: row.name,
result: row.name
}
});
},
formatItem: function(item) {
return format(item);
},
});
});
}




Theme © iAndrew 2016 - Forum software by © MyBB