Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How do I retrieve data from database and put the data in a JavaScript array variable?

user-image
Question added by Yasmeen Husam , Web Developer , Al Fahid Systems
Date Posted: 2019/01/30
Mohammed Touil
by Mohammed Touil , Executive Housekeeper , Université international de Rabat

() { $ajax({ type : 'get', url : 'urlofmyfile.py', dataType : 'json', function(availableNumber){ $( "#items" ).autocomplete({ source: availableTags }); } }); });

Ahmed Hussin
by Ahmed Hussin , Co Founder , Ghadi

 

افضل وسيلة عن طريق$(function() { $.ajax({ type : 'get', url : 'urlofmyfile.py', data : 'q='+q, dataType : 'json', success : function(availableTags){ $( "#items" ).autocomplete({ source: availableTags }); } }); });

Deleted user
by Deleted user

Dear Yasamin,

When you are using AJAX to access DATABASE from HTML or JAVASCRIPT file you are going to have the rsponse as JSON or XML.

$.ajax(

url:"your path"

dataTyp: "JSON/ETC"

success:function(data){

do what ever with data

}

});

Example: If you are using PHP then you have to put function in PHP code to access database and encode the retrieved data in JSON XML or any

function retrieveData(){

/* make connection to database */

$data="SELECT * FROM XTABLE";

$result=json_encode($data);

echo $result;

/* Close connection for prformance and security reasons*/

}

 

 

 

More Questions Like This