I have an small callback-function for an jQuery autocompleation input field. The function has 2 parameters: term=the string, typed into the input field and url=the url to the php script which generates suggestions.
The script looked like that:
function m(term,url) {
var y = '';
jQuery.get(url, { term:term }, function(data){ });
return y;
}
Everything you type into the text-field is send to the php script, which returns a list of suggestions.
Inside the function(data){}
block, two things should be happened:
encode the JSON string into an Array (which is needed by the JQuery autocomplete as return value). I tried this:
y=eval("(" + data + ")");
. Is this right? The JSON string which is generates from the PHP side looks like that (example for term="nur")["nuri al maliki","nursultan nasarbajew","n\u00fcrnberger prozess"] n\u00fcrnberger is the encoded version of "nürnberger"
Highlight the term inside suggested word. Example: input value is "ris" so an suggestion example should be something like
sun<b>ris</b>e
.
Is there a way to use something like .replace
for array?
The application run's under the Yii framework - so I would like to find an solution for that.