Notification texts go here Contact Us Buy Now!

ajax requesting POST error status code 500

Sure, here is the HTML code for the copywriter's response, formatted with a block to represent codes: ```html

The error you are encountering is most likely due to an incorrect URL in your AJAX request. Let's take a look at the structure of your code and identify the issue.

public class ModelClass
{
    public int Id { get; set; }
    public string Name { get; set; }
}
    

This is the model class that represents the data you are sending in your AJAX request.

[Route("api/[controller]")]
[ApiController]
public class ManageEmployeeController : ControllerBase
{

    [HttpPost]
    [Route("Insert_Something")]
    public async Task Insert_Something(ModelClass searchModel)
    {

        return Ok(searchModel);
    }
}
    

This is the API controller that handles the AJAX request. The [Route] attribute specifies the URL that the controller responds to.

$(document).on('click', '#btnSave', function (e) {

    const array = { Id: 1, Name: "Test Name" };
    var data = JSON.stringify(array);
    $.ajax({
        url: '/Api/ManageEmployee/Insert_Something',
        type: 'POST',
        data: data,
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            console.log(result);
        },
        error: function (e) {
        }
    });
});
    

This is the AJAX request that is being sent to the API controller. The url property specifies the URL that the request is being sent to.

Note: window.location.origin +'/Api/ManageEmployee/Insert_Something' is also a valid URL for the AJAX request.

Here is an example of the output that you should see in the console when the AJAX request is successful:

  • enter image description here
  • enter image description here
  • enter image description here

Note: If you have any specific requirements for custom route configuration, please refer to the official Microsoft documentation: Custom Route Configuration.

```

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.