Jump to content

Passing Data To Function


stijn0713

Recommended Posts

I found this autoSuggest plugin that i need to make work like this:

 

$(document).ready(function() {
$(function (){
data = [
{
"name": "hein frank"
}
]
$("#auteur").autoSuggest(data, {selectedItemProp: "name", searchObjProps: "name"});
});
});

 

Now i want to pass the data from this function:

 

function suggest_auteur(inputString){

if(inputString.length != 0) {
$.post("get_json/suggest_auteurs.php", {queryString: ""+inputString+""}, function(data){
alert(JSON.stringify(data, undefined, 2));   --> //[  {	"name": "hein frank"  }]
})
}
}

 

But i struggle to pass it correctly.

Link to comment
https://forums.phpfreaks.com/topic/271103-passing-data-to-function/
Share on other sites

You are passing an array with an array in it. You don't enclose the {} with [] unless you're doing multiple arrays. If you want multiple array with keys then you would be doing {} inside of {}.

 

var data = {
   "name": "hein frank"
};

 

Also, you forget a lot of your delimiters. I know sometimes you can get away with it, but you should just use them all the time to avoid confusion. It doesn't hurt anything to have it, but it can hurt it to not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.