These are chat archives for ushahidi/Community

22nd
Nov 2016
Nesp
@Nesp
Nov 22 2016 14:05
hey there! @ushbot is there a limit to the number of api requests I send?
Ushbot
@ushbot
Nov 22 2016 14:06
[David Losada, Ushahidi] Hi Nesp, no I don’t think we do rate or total limiting
Nesp
@Nesp
Nov 22 2016 14:12
Ok, thanks! I was wondering because all of my api requests work but the last one. It never gets the status 200.
Ushbot
@ushbot
Nov 22 2016 14:12
[David Losada, Ushahidi] What kind of response are you getting?
Nesp
@Nesp
Nov 22 2016 14:12
that's the problem, no response
do you usually get one in javascript if an ajax request fails?
the console is all clean XD
Ushbot
@ushbot
Nov 22 2016 14:16
[David Losada, Ushahidi] yes, there should be a response of some sort in all cases
[David Losada, Ushahidi] maybe it takes a while?
Nesp
@Nesp
Nov 22 2016 14:17
somehow it jumps the part in which the callback function is called, goes back to the html page and refreshes it
:/
Ushbot
@ushbot
Nov 22 2016 14:18
[David Losada, Ushahidi] hm. did you check out the network traffic? i.e. using the Chrome developer tools?
Nesp
@Nesp
Nov 22 2016 14:19
good pooint!
I was checking the debugger but not the network traffic :)
Nesp
@Nesp
Nov 22 2016 14:34

Ok, it stops in an intermediate request. What I am doing is

  1. get a token;
  2. use the token to get a post;
  3. parse the json and update the post by changing a property;
  4. send a put request with the updated post as the body (after converting it back to JSON).

it stops at step 2.
I am debugging and checking the network. There, when it gets to getting the post, if creates a request twice. at first there is written

blob
Ushbot
@ushbot
Nov 22 2016 14:35
[David Losada, Ushahidi] mm are those all the headers? there should be an Authorization one with the token
Nesp
@Nesp
Nov 22 2016 14:35
blob
blob
I am doing the same thing in postman with the same token I get from the previous request in Javascript and it works
Ushbot
@ushbot
Nov 22 2016 14:37
[David Losada, Ushahidi] ok so that one is successful (it’s the OPTIONS header, browsers do that automatically)
[David Losada, Ushahidi] what about the next one? (in red)
Nesp
@Nesp
Nov 22 2016 14:38
it is the same request
seems like it is trying again
Ushbot
@ushbot
Nov 22 2016 14:38
[David Losada, Ushahidi] no not really, it’s something browsers do when the javascript is hosted in a different domain than the api
[David Losada, Ushahidi] we should really study the next on
Nesp
@Nesp
Nov 22 2016 14:38
ok
i'll go one step further f10
and, when I do that the javascript code stops running (even though there is a callback function which should be called and I have a breakpoint there)
if I go to network that's what I see
blob
Ushbot
@ushbot
Nov 22 2016 14:42
[David Losada, Ushahidi] all those requests seem to be successful
Nesp
@Nesp
Nov 22 2016 14:43
I got all the posts
instead of one post
blob
Ushbot
@ushbot
Nov 22 2016 14:43
[David Losada, Ushahidi] looking good
[David Losada, Ushahidi] we should go back to the one that was failing before
Nesp
@Nesp
Nov 22 2016 14:44
blob
this is the url I use in the ajax request
(ok)
(thanks!)
Ushbot
@ushbot
Nov 22 2016 14:46
[David Losada, Ushahidi] did you figure it out?
Nesp
@Nesp
Nov 22 2016 14:48
(nope)
this is the one failing you where talking about, I guess but I am not sure :D
blob
blob
Ushbot
@ushbot
Nov 22 2016 14:51
[David Losada, Ushahidi] mm yea seems to be
Nesp
@Nesp
Nov 22 2016 14:53
and then when I go one step forward, I find that I got all the posts instead of 1
but it stopped running and it did not call the callback function
this is fun :D
Ushbot
@ushbot
Nov 22 2016 14:56
[David Losada, Ushahidi] mm yea I don’t see anything wrong with that request
[David Losada, Ushahidi] it’s a bit of a head scratcher
Nesp
@Nesp
Nov 22 2016 15:10
while this is the result in postman
blob
Ushbot
@ushbot
Nov 22 2016 15:16
[David Losada, Ushahidi] same for posts/2 ?
[David Losada, Ushahidi] my guess is that the javascript code is where it’s at
[David Losada, Ushahidi] if you’ve programmed all the XMLHttpRequest calls yourself, I’d try to look at that with fresh eyes
Nesp
@Nesp
Nov 22 2016 15:27
blob
same for posts/2
ok thanks for the advice!
it's a little tricky because I have one function that does all the calls, but then all of them are different
perhaps I should use jquery
Ushbot
@ushbot
Nov 22 2016 15:54
[David Losada, Ushahidi] using jquery or something that makes XMLHttpRequest easier could be a good idea indeed
Nesp
@Nesp
Nov 22 2016 16:02
:+1: