php - Ajax error when retrieving data from JSON -
php - Ajax error when retrieving data from JSON -
i trying send info php file inserts values in db (this part ok) , send json encoded info javascript file can display them not working. not know wrong. i've been looking @ many working examples , mines not working.
$.ajax({ type: "post", datatype: "json", url: "requete.php", data: data, success: function(data) { if (data.success == true) { alert(data.message); } }, error: function(errorthrown) { alert('error'); } });
data correctly sent php , inserted in db next json won't display :
if (isset($_post['action']) && $_post['action'] == 'add_attribution') { $nom = $_post['nom']; $date = $_post['date']; $montant = (int)$_post['montant']; $type = utf8_decode($_post['type']); $sql = "insert bo_depenses (montant,date,personne,description,carte) values('$montant','$date','','$nom','$type')"; $result = mysql_query($sql); $data = array('success'=> true,'message'=>'success message: hooray!'); echo json_encode($data);
with code, console returns "object" info sent php/mysql ( ?? )
thanks help
update : managed json result putting in error:
var obj = json.stringify(data) alert(obj);
it turns out displays first values sent php script (to insert in db) , not 1 json encoded... why ?
try using
if ($.trim(data.success) == 1)
sometimes have faced simillar situation advertisement solved using this
php jquery ajax json
Comments
Post a Comment