javascript - Passing variable value from one function to another in autocomplete with AJAX call -
I have a problem in using auto-complete jQuery with AJAX calls when the user types something in the input field, So I give that value to AJAX with the controller where I get values from the database and then send all these values to Javascript in the success message. But after that, I have a problem using these JSON values to auto-complete, how to fix it?
View file
& lt; Link rel = "stylesheet" href = "// code.jquery.com/ui/1.11.0/ topics / lubricity / jQuery-ui.css" & gt; & Lt; Script src = "// code.jquery.com/jquery-1.10.2.js"></script> & Lt; Script src = "// code.jquery.com/ui/1.11.0/jquery-ui.js"></script> & Lt; Link rel = "stylesheet" href = "/ resources / demos / style.css" & gt; & Lt; Script & gt; $ (Function () {$ ("# tag"). Autocomplete ({source: function (request, response) {$ .ajax ({type: "POST", url: "& lt ;? php echo base_ url" (). 'Index.php / search_con / user';? & Gt; "Data: {'userA': request.term}, success: function (message) {var a = [" Central Palms Hotel "," Hotel Monalisha "," Asggjfddas "," my hotel added "," asdfsdf "," asdsadsa "]; response (a); // alert (message);}}}}}});}); & Lt; / Script & gt; & Lt; Div class = "ui-widget" & gt; & Lt; Label = "tag" & gt; Tags: & lt; / Label & gt; & Lt; Input id = "tag" & gt; & Lt; / Div & gt;
and Administrator
Public function user () {$ userPart = $ _POST ['userA']; $ Result = $ it- & gt; Search-db- & gt; Search ($ userPart); $ List = array (); Forex Currency ($ result $ as the final data) {$ data = $ finaldata-> Name; Array_push ($ list, $ data); } Echo json_encode ($ list); }
Now my problem is that when I remove the static variable and use the msg for the response, nothing is shown in the autoclipate data and when I get the warning message I get data similar to variables. Is there any mistake in my Jason?
You do not need a separate function to fetch data, for automatic integer, ({Source: function (request, response) {$ .post ("& lt ;; php Echo base_url (). 'Index.php / search_con / user' ;? Gt; ", {userA: request.term}, response);}});}); You can not do this because of
and async
$ Ajax ({type: "POST", Url: "& lt ;? php echo base_url (). 'Index.php / search_con / user'; & gt;", data: data string, breakthrough: function (message) {data = Msgs;}}); Warning (data); // undefined
Comments
Post a Comment