Getting the error "JSONP entered by script did not call a callback." using Angular 2 and the ASP.NET server core

I am using Angular 2 on the client side and on the server side of the Asp.NET web API core.

I made simple mail calls from the Angular 2 client to the main ASP.NET web API, as shown in the code below.

this.http. post("/api/Patient", data, options) .map(res => res.json()) .subscribe( res => this.CallBack(res), err => this.logError(err)); 

My main ASPAP code for ASP is server side as below.

 public IActionResult Post() { // I am using EF and inserting to DB // Till here everything works fine. return Ok(obj); } 

When the message occurs, we get the error below

Net :: ERR_CONNECTION_RESET

Data is inserted, but when the object is returned, the server simply refuses. Also, when I delved into the error, I saw below.

"The JSONP entered by the script did not call the callback." JSONP_ERR_WRONG_METHOD: "JSONP requests must use the GET request method." JSONP_HOME

In my local mode, it works, and sometimes it crashes. I am currently posting on http://www.smarterasp.net and this error is frequent on this server.

Any pointers are welcome.

+6
source share
1 answer

I know that sounds funny. But the fix is ​​as in POST, and not the return of the object, we sent a serialized JSON string.

 public string Post() // <-- this was first a object we changed to string { // I am using EF and inserting to DB // Till here everything works fine. return SerializedString; } 

We are sure that this is due to problems with posting on the website www.smarterasp.net.

0
source

Source: https://habr.com/ru/post/1014564/


All Articles