2

here is the response code

echo json_encode( array('success' => $stat,'msg'=>$file));

return from the server response

Object {success: "success", msg: "2017_nissan_gtr-2560x14409.jpg"}
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
MN Asghar
  • 35
  • 4

4 Answers4

3
var response = {success: "success", msg: "2017_nissan_gtr-2560x14409.jpg"}
var success = response.success;
var msg = response.msg;
spyshiv
  • 178
  • 1
  • 8
1

You can iterate object by below code.

var obj= {success: "success", msg: "2017_nissan_gtr-2560x14409.jpg"}
for(var i in obj)
{
 alert(i+" :: "+ obj[i]);
}
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
0

You can use Object.keys():

var respObj = {
  success: "success",
  msg: "2017_nissan_gtr-2560x14409.jpg"
}
Object.keys(respObj).forEach(function(k) {
   console.log('key::::>', k,' value::::> ', respObj[k]);
})
Jai
  • 74,255
  • 12
  • 74
  • 103
0

U can iterate through the object properties using the following code..

 $.each(obj, function (key, value) { });
Karthikeyan
  • 347
  • 3
  • 8