Search code examples
javascriptrestcallbackasynccallback

How set a url(callback) to listen a answer by javascript


Currently, I am consuming a rest service that has a signature

http://service.ip/auth?clien=xx&redirect=URIXX

where URIXXX shall be

  http://localhost:8080/auth/callback

I wonder if it is possible to open a "URIXXX" in a javascript in order to received the answer from the server? Like a callback?


Solution

  • If the scripts employs JSONP then yes, otherwise declare a HTTPRequest and then parse then extra stuff out of the return and inject the contents into the head of your document in a wrapper function which opens a window indicated and the writes the needful scripts / content into the newly created window...

    If you mean you are trying to tell your request to go to another location for the response I would suggest you check out my WebServer Class which supports Comet style interactions...

    https://net7ntcip.codeplex.com/SourceControl/changeset/view/89621#1752948

    After you submit the request you can then receive in the response the location to addition to a token... You can take this token and send it to the page indicated in the response and then you will have achieved what you wanted to do..

    I suppose the same technique could be employed to do the same thing without my web server...