1
Hello
I’m having trouble with the JSON
when I climb it to the server..
Example of one of my code they use JSON
:
$("input[name=people]").keyup(function(){
if($(this).val() != ''){
$.ajax({
url: "<?php echo site_url('/StockController/searchPeople')?>",
type: "POST",
cache: false,
data: {name_people: $(this).val()},
success: function(data){
$('#loadPeople').html("");
var obj = JSON.parse(data);
if(obj.length>0){
try{
var items=[];
$.each(obj, function(i,val){
items.push($("<option id="+ val.id_people +">"+ val.name +"</option>"));
});
$('#loadPeople').append.apply($('#loadPeople'), items);
}catch(e) {
alert('Ocorreu algum erro ao carregar os Fornecedores!');
}
}else{
$('#loadPeople').html($('<span/>').text("Nenhum Fornecedor encontrado!"));
}
},
error: function(data){
alert("Ocorreu algum erro ao carregar os Fornecedores");
}
});
}else{
$('#loadPeople').html(" ");
}
});
On the local server it runs smoothly, but when I go online the code stops working, and returns the following error on the console:
Uncaught Syntaxerror: Unexpected token in JSON at position 0
Does anyone know what might be going on?
you have how to post what comes out on your console.log() to the JSON you want to handle?
– pmargreff
[{"id_product":"142","name_product":"Carregador de Celular Gen\u00e9rico","unit_price":"10.00"},{"id_product":"143","name_product":"Arroz Itatibaia","unit_price":"4.00"},{"id_product":"145","name_product":"Feij\u00e3o","unit_price":"10.99"},{"id_product":"146","name_product":"pao","unit_price":"12.00"}]
– zyzzete
This.log() console is from the server or localhost?
– wmarquardt