I have the following code that searches the characters typed in the search box with the onkeyup event.
$("#keywords").keyup(function () {
var kw = $("#keywords").val();
if (kw != '') {
var url = "<?php echo base_url().'index.php/simpromotions/livesearch/';?>" + kw;
$.ajax({
type: "POST",
url: url,
datatype: "json",
success: function (data) {
**alert(data);**
$.each(data,function(ptitle, category){
$("#results").html('<label>'+ptitle+': '+category+'</label><br>');
}
}
});
}else{
$("#results").html("");
return false;
}
});
In the above code when I alert the data it displayes the following array string.
{"pcode":"22","category":"NightTalk","ptitle":"HourlyNightTalk"}
I cant seem to access the pcode, category and ptitle as I have done in the next line. (after alert)
Please help me how I can access the three!