New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"JSONP injected script did not invoke callback." #8153
Comments
You didn't provide the callback in your request. In the following sample, the query parameter to provide the callback is
|
@templth nope still an error this._jsonp.request('http://localhost:3000/calendar/2016/4', { method: 'Get' })
.subscribe(
(data) => {
console.log(data);
},
(error) => {
console.log(error);
}); and this is in my app.js for nodejs server app.get('/calendar/:year/:month', function (request, response) {
response.jsonp(createYear(2016)); // returns an object
)}; |
Did you get a solution, I have the same problem |
I was able to recreate this problem in a Plunker here. What looks like is happening is that angular/modules/@angular/http/src/backends/jsonp_backend.ts Lines 78 to 86 in a66cdb4
JsonpConnection_ - I think some logic needs to be added where upon completion of the request (whether aborted, completed, or cancelled), it has to call this.finished .
This also seems to indicate that the error message is busted even in the event the request is aborted or cancelled. |
in http.umd.js on line 1425 you have the following code:
This means you must have the string '=JSONP_CALLBACK&' in your url for angular to replace the JSONP_CALLBACK string with its generate function which eventually will call your success function upon success. |
mbakker96: Since you use the
|
@wesleycho In fact I don't think that there is a problem here. The callback is internally managed by Angular2 but you need to specify the Under the hood Angular2 will update the URL like this:
This way the See this plunkr: http://plnkr.co/edit/Sn7ml5Omzoz3DrnumCnt?p=preview. |
for angular 2 stable latest release jsonp crud sample please |
which you told is right. i need to fix backend api |
Still think this issue should be in the Angular 2 documentation for others trying to use jsonp to sidestep cors issues or leverage jsonp |
I am a newbie to Angular 2. I am really confused. I am using .NET Web Api as my server code and it returns Json data. On the client end, i am fetching the data using Jsonp. I am able to see the data coming (Status : 200) using Inspect element Network tab in Chrome. But my returned Observables from service flowing to the error section in my subscribe method. Below is the error message. Please help me out. Note: I do have a function mycallback in my service. errorMessage: |
It sounds like what is confusing you is what confused me. Your function does not need to be called "mycallback". It needs to pass back the json data in a function whose name angular passes in mycallback. In this case "_ng_jsonp.__req6.finished". After unpacking the json angular receives back _ng_jsonp.__req6.finished({mystuff:'yeah'}). It is possible I am doing it wrong but after a day banging my head against the wall it works |
in the backend you return data must be present this following form |
Thanks guys. @sambanthar @Nicholas-Westley Earlier my api gives me Json data instead of Jsonp. |
url: "http://localhost:8000/?callback=__ng_jsonp__.__req0.finished" |
@templth I specified the callback, and I still have the problem
|
i solved the problem:use |
Anything on this? Same issue.
|
@templth Why can not call Angular2's JSONP_CALLBACK handler? |
If a page contains multiple components, jump to another route, and then return to the original page, $ {this.times} can not be calculated, there will be an error, why JSONP_CALLBACK can not call the angular2 inside the processing function? |
Angular is replacing JSONP_CALLBACK with Inspect your Network response. If you see Also, some services have different requirements for the callback query string parameter, which proves to be nasty because the error is exactly the same. I was using |
When hardcoding the Jsonp callback (re: JSONP_CALLBACK issue) you need to account for the number of calls made, as Angular persists the state of each call. An example of what I'm doing for Mailchimp:
|
This solution i have used on instagram rest api call let params1 = new URLSearchParams();
This one working plz check |
Is there any update on this issue? The issue I am having is simular to the issue @danmcclure already mentioned. Except when using the _'ng_jsonp._req' + jsonpCalls + '.finished'-trick I still get the same error. So, the call is succesfull but again JSONP injected script did not invoke callback. is the error which is returned when trying to subscribe... |
No found solution for this. |
Is there any solutions for this ?? i am trying in ng-4. Whichever way we try we are getting the same old error |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I created a JSONP request in angular 2 / ionic 2 to get a json object but when I run it I get a error in my console.
This is the code where I make the reqeust
Current behavior
Gives an error:
Expected/desired behavior
Return an empty JSON object:
{ }
Other information
I run angular 2 beta 14 with ionic 2.
The text was updated successfully, but these errors were encountered: