I make form submit, when I check in console it returns JSON data. But I can't use object in JSON data.
$('#ff').form({
type: 'POST',
cache: false,
url: base_url + 'Api/lapor/submit',
dataType: 'json',
iframe: false,
onSubmit: function(param) {
param.id_item = sessionStorage.id_item;
param.token = sessionStorage.token;
},
onProgress: function(percent) {
$.messager.progress();
},
success: function(msg){
console.log(msg.status); //it will return undefined
$.messager.progress('close');
},
onLoadError: function(){
$.messager.alert('Error', 'Gagal', 'error');
}
});
I try console.log(msg) and it return JSON data
console
When you log the return message using
console.log(msg.status);, if it write the result as{message: "Data 1 telah disimpan", status: true}then you can call it by using eithermsg.statusormsg['status']But in your case it's logged as
{"message": "Data 1 telah disimpan", "status": true}, so you should try calling it with the"included likemsg['"status"']ormsg["\"status\""]Update Here's the difference between the
msg1andmsg2when logged usingconsole.logUpdate 2 Because the return type of
jeasyui$.formis astring, so you need to parse it first to a JSON / javascript object by usingJSON.parseor the one found in thejeasyuidocs section Handle submit response here