API Consume data getting 500 Err.

Aypn CNN 446 Reputation points
2023-02-22T07:25:55.5433333+00:00

Hi,

Please refer my below mentioned code, where I did mistake? I am getting following err.,

Similar this https://www.aspsnippets.com/questions/189822/Send-authorization-headers-to-Web-API-using-jQuery-Ajax-in-ASPNet/ I prepared my script.

Error is;

jquery-3.5.1.min.js:2 GET https://example.com}&_=10441 net::ERR_ABORTED 500 (Internal Server Error)

Indicate whether a cookie is intended to be set in a cross-site context by specifying its SameSite attribute

Indicate whether to send a cookie in a cross-site request by specifying its SameSite attribute


refer my Code:
 
        function getmInfo() {
                $.ajax({
                type: "POST",
                url: "https://example.com",
                data: '{"Method":"GetAPIData","ID":"1007"}',
                contentType: "application/json; charset=utf-8",
                dataType: "jsonp",
                headers: {
                    'Authorization':'test2121:8.3',
                    'Key':'test01011',
                    'Value':'test',
  		    'Access-Control-Allow-Origin': '*',
                    'Access-Control-Allow-Headers': 'Origin,X-Requested-With',
                    'Accept': 'application/json',
                    'Access-Control-Allow-Methods': 'GET',
                    'Access-Control-Allow-Credentials': 'true'

                },
                success: function (response) {
                    console.log(response.d);
                    var result = response.d;
                    if (result == '200') {
                        alert("Great!");
                    }
                    else if (result == '400') {
                        alert("Sorry, err");
                    }
                    else {
                        alert("Sorry! !");
                    }
                },
                error: function (data, ex) {
                    alert("Sorry there is err. " + data + " Ex: " + ex);
                 }

            });
        }

Developer technologies | ASP.NET | ASP.NET API
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.