-1

I am using $.post() to get ajax data from the server.

$.post({
   type: 'POST',
   url: 'http://<ip-address>/app/path/example.htm',
   data: {<proper data getting sent>},
   dataType: 'json',
   encode: true
   })
.done(function(data){
    console.log(data);
     ---- Do Stuff ----
})

Now in the inspector in Chrome I can see the json being returned from example.htm. There is a value in each record that is 0. There is 60 records getting returned and 1 record has Overdue: 1 and all the other records have Overdue: 0. When I check the console to see the log dump every record has overdue of 1. Every single other value in the record is untouched, but Overdue is getting changed from 0 to 1 between the server sending a 0 and the .done() console.log showing a 1.

Why is it getting changed to a 1, it should stay a 0? is there something I'm missing?

[EDIT] 1. The Do stuff part is processing the data object, and would have no effect on the data object.

  1. The server side code at the url given in the $.post returns a serialized JSON struct and looks like this

    {"list":[ {"ID":26,"CREATEDON":"2018-12-31 13:22:34.233 -06:00","FIRST_NAME":"shawn","LAST_NAME":"Smith","OVERDUE":1,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":27,"CREATEDON":"2018-12-31 13:22:58.810 -06:00","FIRST_NAME":"john","LAST_NAME":"Jones","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":28,"CREATEDON":"2018-12-31 13:43:04.793 -06:00","FIRST_NAME":"paul","LAST_NAME":"Doe","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":59,"CREATEDON":"2019-01-05 11:36:17.887 -06:00","FIRST_NAME":"David","LAST_NAME":"Smith","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":60,"CREATEDON":"2019-01-05 11:37:52.873 -06:00","FIRST_NAME":"fred","LAST_NAME":"Jones","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":65,"CREATEDON":"2019-01-05 11:50:26.360 -06:00","FIRST_NAME":"harry","LAST_NAME":"Doe","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":66,"CREATEDON":"2019-01-07 09:26:22.617 -06:00","FIRST_NAME":"rick","LAST_NAME":"James","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":70,"CREATEDON":"2019-01-10 09:15:51.707 -06:00","FIRST_NAME":"Jane","LAST_NAME":"Smith","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":71,"CREATEDON":"2019-01-10 09:18:39.630 -06:00","FIRST_NAME":"Jill","LAST_NAME":"Smith","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":72,"CREATEDON":"2019-01-10 09:26:01.330 -06:00","FIRST_NAME":"Betty","LAST_NAME":"White","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":73,"CREATEDON":"2019-01-10 09:28:16.757 -06:00","FIRST_NAME":"Sue","LAST_NAME":"white","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":74,"CREATEDON":"2019-01-10 09:28:35.617 -06:00","FIRST_NAME":"Sally","LAST_NAME":"blue","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":75,"CREATEDON":"2019-01-10 09:43:06.843 -06:00","FIRST_NAME":"Megan","LAST_NAME":"smith","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}, {"ID":76,"CREATEDON":"2019-01-10 09:51:21.650 -06:00","FIRST_NAME":"Lillian","LAST_NAME":"test","OVERDUE":0,"UTCDATETIME":"February, 07 2019 23:32:39"}],"errors":{}}

You can see that only 1 record has OVERDUE:1 Now the console.log(data) should dump this data, but somewhere along the line it is changing to a 1 for all records. As seen here in the console log dump.

leadslist: Array(61)
0:
CREATEDON: "2018-12-31 13:22:34.233 -06:00"
FIRST_NAME: "shawn"
LAST_NAME: "Smith"
ID: 26
OVERDUE: 1
UTCDATETIME: "February, 07 2019 23:32:39"
__proto__: Object
1:
CREATEDON: "2018-12-31 13:22:58.810 -06:00"
FIRST_NAME: "john"
LAST_NAME: "Jones"
ID: 27
OVERDUE: 1
UTCDATETIME: "February, 07 2019 23:32:39"
__proto__: Object
2:
CREATEDON: "2018-12-31 13:43:04.793 -06:00"
FIRST_NAME: "paul"
LAST_NAME: "Doe"
ID: 28
OVERDUE: 1
UTCDATETIME: "February, 07 2019 23:32:39"
__proto__: Object
3:
CREATEDON: "2019-01-05 11:36:17.887 -06:00"
FIRST_NAME: "David"
LAST_NAME: "Smith"
ID: 59
OVERDUE: 1
UTCDATETIME: "February, 07 2019 23:32:39"
__proto__: Object

My question is why isn't the 0 getting carried through, I might not be asking the question correctly, but it doesn't make any sense to me at all. Every value is getting brought through but the zero in OVERDUE is not. The Do Stuff part takes this data and builds a table that is displayed on screen, no further processing happens to the data. But besides, I have the code set up exactly as shown above. If there was processing with in the do stuff, it wouldn't show in the console.log this is javascript it couldn't do processing after the console dump and have that show up in the dump.

Shinn
  • 27
  • 4
  • 1
    If there is any logic that changes the object that you console log, the browser is going to show you the up to date value of the object in the console, not what came from the request. The browser is "helpful" to you like that. – Taplar Feb 07 '19 at 23:55
  • 1
    Please read [ask] and create a [mcve]. Your example doesn't explain or demonstrate anything about the issue you just described – Alon Eitan Feb 08 '19 at 00:01
  • Considering that people are coming from all levels of experience, I think the example given by the OP is an adequate, earnest attempt to describe their issue. – g.carey Feb 08 '19 at 00:22
  • 1
    No, that example is useless and that is a fact – Alon Eitan Feb 08 '19 at 00:36
  • 1
    https://stackoverflow.com/conduct let's be nice @AlonEitan – g.carey Feb 08 '19 at 00:43
  • 2
    I was being nice and still am. You don't know what is that `---- Do Stuff ---` part, you don't know what is the response from the server, you don't know anything from this question. We don't need to sugarcoat everything all the time – Alon Eitan Feb 08 '19 at 00:46
  • The Do Stuff happens after the console dump so wouldn't change what is being dumped. I updated my question with the JSON being sent from the server and what the console dump looks like. There is no step in my code where the data should be changed, so I don't know why the data is being changed. – Shinn Feb 08 '19 at 15:18
  • 1
    @AlonEitan my apologies you were right sort of, the issue was in the `---- Do Stuff ----` – Shinn Feb 08 '19 at 16:22

2 Answers2

2

Upon further investigation I found that my if statement that happens after the console.log was wrong. I missed the second equals sign so it was setting the value. Which is odd since it was happening after the dump to the console, so I went searching for why the console would show changes made after it is called and found. https://stackoverflow.com/a/24176638/11031165

There is a really old bug in chrome which was causing my issue to look like it was getting caused in a different place than it really was.

Shinn
  • 27
  • 4
0

It looks like this is a backend/api issue (not frontend), and has nothing to do with .done(). The server processing the POST request is likely updating the value. If you have access to it, check out the server code that processes requests to this endpoint, and try to figure out why the value is getting changed.

g.carey
  • 690
  • 9
  • 6