← 输入框|github.com|刷新
Skip to content

Jsonp error Uncaught ReferenceError: __ng_jsonp____req0_finished is not defined after https://github.com/angular/angular/pull/13219 #14267

Closed

Description

@doxiaodong

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

hello, after upgrade to 2.4.6, I get Uncaught ReferenceError: __ng_jsonp____req0_finished is not defined as #13219 (comment)
image

Plunkr
http://plnkr.co/edit/WcRnPrJHa04rJy3xTIky?p=preview

And my code is

search(key: string) {
  const params = new URLSearchParams()
  params.set('key', key)
  params.set('jsonpCallback', 'JSONP_CALLBACK')
  return this.jsonp.get('https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?' + params)
  .toPromise()
  .then(res => {
    console.log(res)
    return []
  })
}

Activity

  1. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    Pls add a plunkr with repro

  2. doxiaodong commented on Feb 3, 2017

    @doxiaodong
    Author
  3. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    Callback must have dot before finished __ng_jsonp____req0.finished

  4. doxiaodong commented on Feb 3, 2017

    @doxiaodong
    Author

    @DzmitryShylovich , I make a simple pr to fix. If you have a better way, close this.

  5. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    I'll take a look thx

  6. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    btw discussion about dot in callback names from ng1 angular/angular.js#1551 (comment)

  7. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    Ok I think I have a better solution.
    First of all we need to revert 9e5617e commit.

    To avoid dots in callback name we need to add callback into the global namespace. I don't like the idea to pollute global namespace by default. So we should expose BrowserJsonp as a DI token (currently it's injectable but not exported) so users can provide their own implementation (or extend and override particular methods) with their own callback names etc.

    @mhevery what do you think about that?

  8. dejour commented on Feb 3, 2017

    @dejour
    Contributor

    but implementation function name is always finished.so i think JSONPCALLBACK is fine. all user care about is returned data.

  9. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor

    @dejour callback name must end with .finished. Some apis don't allow callback names with dots. To avoid dots we need to add callbacks directly to window. Don't think polluting window by default is a good idea

  10. doxiaodong commented on Feb 3, 2017

    @doxiaodong
    Author

    Greate, I make an example with no dot about @DzmitryShylovich 's pr.

    1. make custom-browser-jsonp.ts
    import { BrowserJsonp } from '@angular/http'
    
    function getJsonpCallbackName(id: string): string {
      return `__custom__ng__jsonp${id}__`
    }
    
    export class CustomBrowserJsonp extends BrowserJsonp {
      requestCallback(id: string): string {
        return getJsonpCallbackName(id)
      }
    
      exposeConnection(id: string, connection: any): void {
        window[getJsonpCallbackName(id)] = connection.finished.bind(connection)
      }
    
      removeConnection(id: string): void {
        window[getJsonpCallbackName(id)] = null
        // or delete window[getJsonpCallbackName(id)]
      }
    }
    
    
    1. in you module
    import { BrowserJsonp } from '@angular/http'
    import { CustomBrowserJsonp } from './custom-browser-jsonp'
    
    @NgModule({
      providers: [{
        { provide: BrowserJsonp, useClass: CustomBrowserJsonp }
      }]
    })
    export class AppModule { }
    
  11. Klerith commented on Feb 9, 2017

    @Klerith

    What is the status of this issue?
    I have the same problem using jsonp module

    image

    image

  12. DzmitryShylovich commented on Feb 9, 2017

    @DzmitryShylovich
    Contributor

    @Klerith will be fixed in the next release. Use 2.4.5 version of http module

  13. Klerith commented on Feb 9, 2017

    @Klerith

    Thank you for the super fast reply @DzmitryShylovich ,

    But for my bad luck, still doesn't work, I update to @angular/http@2.4.7, even delete and make the npm to recreate that folder, but still get the same error.

    Or maybe I am doing something wrong, ( I am using Angular-CLI "version": "1.0.0-beta.28.3")

    Thank you for anything you can tell me

    image

  14. DzmitryShylovich commented on Feb 9, 2017

    @DzmitryShylovich
    Contributor

    @Klerith the bug was introduced in 2.4.6. So you need to use 2.4.5

  15. Klerith commented on Feb 9, 2017

    @Klerith

    @DzmitryShylovich, If you live in Costa Rica, I will invite you to a good coffee for this excellent support.

    I will use that HTTP version (2.4.5) until I the next release comes out.

    Thank you so much! That fixed my issue.

  16. gastonkirsman commented on Feb 10, 2017

    @gastonkirsman

    @DzmitryShylovich Great!
    With @angular/http 2.4.5 jsonp requests work.

  17. DzmitryShylovich commented on Feb 18, 2017

    @DzmitryShylovich
    Contributor

    @doxiaodong the commit that caused this bug was reverted so it can be closed

  18. doxiaodong commented on Feb 20, 2017

    @doxiaodong
    Author

    close

  19. erneledesma commented on Feb 12, 2019

    @erneledesma

    Hi all! I have the following problem to want to make the request .. I do not realize about the error..
    I appreciate any suggestions
    captura de pantalla 2019-02-12 a la s 20 22 23
    captura de pantalla 2019-02-12 a la s 20 22 43
    captura de pantalla 2019-02-12 a la s 20 34 18

  20. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  21. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions