0

Trying to get a single object returned by request using callbacks. Callback

Error:undefined Data:[object Object] Why are there two objects being returned when I am returning only one error and one object?

wick3d
  • 1,164
  • 14
  • 41
  • 2
    Instead of undefined, please send `null`. – MiKr13 Apr 30 '20 at 03:09
  • @MihirKumar Sending a error as null when there is no error.Callback prints null. But I am not getting the object. Error:null Data:[object Object] Didn't get it. Can you please elaborate – wick3d Apr 30 '20 at 03:14
  • Instead of null everywhere you need to use null & JSON.stringify the data you are sending and then JSON.parse it again in geoCode – MiKr13 Apr 30 '20 at 03:57
  • 1
    Please post code as text, not as images. When you post it as an image, it won't be indexed for search, people trying to write answers can't copy your code into an answer and fix/modify it and its much harder to deal with on mobile devices. Please post code as text. – jfriend00 Apr 30 '20 at 04:08
  • I tried formatting,there were too many indentation errors. I moved a few spaces and the code was not readable. – wick3d Apr 30 '20 at 04:12

1 Answers1

1

Actually, there is only one object being returned from the callback. The reason why [object Object] is printed, is because that is the default serialization of an object.

You can see this answer for a detailed explanation:
what does [object Object] mean?

To print the data contained in the object, you can JSON.stringify it like this:

    console.log("Data:"+JSON.stringify(data))
Kashinath Patekar
  • 1,083
  • 9
  • 23