Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Unable to call Web API service in Chrome and Firefox

$
0
0

I implemented web API service, which includes a POST method. Implemented OWIN Authentication, CORS, Error handling features on it.

I tested in my local box which works well in all browsers: IE, Chrome and Firefox.

The same code I published and pushed into UAT server for testing, API service is not working in Chrome and Firefox, but works well in IE. I called this API service using JQuery from demo.html page. please find my JQuery code snippet.

<script language="javascript" type="text/javascript">$( document ).ready(function() {$("#myButton").click(function(e){
	callingAPI();
	e.preventDefault();
	});
});

        var DataModel = {
            Id: 1,
            Aray: [{
                Id1: "XXXXXXX@xxx.com",
                Id2: 1,
                Id3: [3],
                Text: ""
            }]
        };

        function callingAPI()
        {
			var accesstoken="";$.ajax({"async": true,"crossDomain": true,"url": "http://xx.xx.xx.xxxx:xxxx/token","method": "POST","headers": {"content-type": "application/x-www-form-urlencoded","cache-control": "no-cache",
				  },"data": {"username": "xxxx","password": "xxxx","grant_type": "password"
				  },"processData": false,
				success: function (data) {
					SubmitData(data.access_token);

                },
                error: function (request, message, error) {
                    alert("error");
                }
            });
        }


		function SubmitData()
		{
		var token="";
		var bearertoken = "Bearer  "+token;
		alert(bearertoken);$.ajax({"async": true,"crossDomain": true,"url": "http://xx.xx.xx.xxxx:xxxx/api/data/submit","method": "POST","headers": {"Content-Type":"application/json","Accept": "application/json","Cache-Control": "no-cache","Authorization": bearertoken,"Access-Control-Allow-Origin" : "*"
							},"dataType": "json","processData": false,"data": JSON.stringify(DataModel),
				success: function (results) {
					alert("Created");
                },
                error: function (request, message, error) {
                    alert(error +", "+message+", "+error);
					alert("error");
                }
            });
		}</script>

could you please help me to come out from this issue, appreciate your suggestions.


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>