php - Jquery function cant access json object -


i'm using bootstrap validator validate form data. if form validated i'm posting data php. in php i'm returning json string. though post success , correct response, can't access json object.

$('#dealform')     .bootstrapvalidator({         message: 'this value not valid',         fields: {             deal_description: {                 message: 'the deal discription not valid',                 validators: {                     notempty: {                         message: 'the deal discription required , can\'t empty'                     }                 }             }         }     })     .on('success.form.bv', function(e) {         // prevent form submission         e.preventdefault();          // form instance         var formobj = $(e.target);          var formurl = formobj.attr("action");          $.ajax({             url: formurl,             type: "post",             data:  new formdata(this),             contenttype: false,             cache: false,             processdata:false,             datatype:json         }).done(function(data) {                 console.log(data);             });     }); 

debugger output

enter image description here

php

$temp= $_post['deal_description'];         if(!empty($_files['userfile']['name'])){$temp2='has';} else $temp2='no has';         echo json_encode(array(             'message' => $temp,             'test' => $temp2         )); 

either set correct header in php:

header('content-type: application/json'); echo json_encode(array(         'message' => $temp,         'test' => $temp2     )); 

or use json.parse in js:

}).done(function(data) {     data = json.parse(data);     console.log(data);     alert(data.mesage);         }); 

edit noticed have spelling mistake in js. data.mesage should have 2 s data.message


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -