i have webservice method takes id of element determine source autocompletes.
in nutshell, i'm doing this:
$("input[type='text']").autocomplete({ source: function(request, response) { var id = $(this).attr('id'); var params = {'id': id, 'term': request.term}; var jsonparams = json.stringify(params); $.ajax({ type: "post", url: "page.aspx/getautocompletelist", data: jsonparams, contenttype: "application/json; charset=utf-8", datatype: "json", success: function(msg) { response(json.parse(msg.d)); }, error: function() { response([]); } }); } });
but id
isn't referring original selector.
what can id of selected input
element? or better strategy this?
try
$(this.element).prop("id"); this.element[0].id; $(this.element.get(0)).attr('id');
$("input[type='text']").autocomplete({ source: function(request, response) { var id = $(this.element).prop("id"); var id2=this.element[0].id; var id3=$(this.element.get(0)).attr('id'); console.log(id); console.log(id2); console.log(id3); var params = {'id': id, 'term': request.term}; var jsonparams = json.stringify(params); $.ajax({ type: "post", url: "page.aspx/getautocompletelist", data: jsonparams, contenttype: "application/json; charset=utf-8", datatype: "json", success: function(msg) { response(json.parse(msg.d)); }, error: function() { response([]); } }); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <input type="text" id="asd"></input>
Comments
Post a Comment