I have the code below that I run from http://localhost to make an API request. The api request gets redirected but I end up in error method instead of getting a response back from redirected url. Is there a way to just follow the redirect and get a response back from redirected url?
<script>
$.ajax({
url: "http://example.phppointofsale.com/index.php/api/v1/items",
type: "GET",
crossDomain: true,
dataType: "json",
headers: {"x-api-key" :
"KEY"},
contentType: "application/json; charset=utf-8",
error: function(request, status, error){
alert("Error: "+error);
},
success: function(request, status) {
console.log("Request: "+JSON.stringify(request));
alert('Success');
},
});
</script>
Output is an alert
Error:
Request Headers
Request URL: http://example.phppointofsale.com/index.php/api/v1/items
Request Method: OPTIONS
Status Code: 307 Temporary Redirect
Remote Address: 54.172.38.136:80
Referrer Policy: no-referrer-when-downgrade
Response Headers
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, x-api-key
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE
Access-Control-Allow-Origin: *
Cache-Control: no-cache, no-store, must-revalidate
Connection: Keep-Alive
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Fri, 30 Nov 2018 15:52:32 GMT
Expires: 0
Keep-Alive: timeout=5, max=100
Location: http://example.phppointofsale.com/PHP-Point-Of-Sale-Prev/index.php/api/v1/items
Pragma: no-cache
Server: Apache
X-Powered-By: PHP/5.6.36
Comments
Post a Comment