Not able to fetch headers via AJAX calls - ajax

I have added the following to server-side API.
header('Access-Control-Allow-Headers: temp');
header('Access-Control-Expose-Headers: temp');
header('temp: 12345');
When I am making a cURL request to the API, I get the headers along with the response-data.
But when I am making an AJAX call to the same API, I only get the data, without the header.
Thanks in advance.
Regards,
Anish

You can retrieve the headers in an AJAX request by calling the getAllResponseHeaders() method on the XHR object. The reference is here

Related

Is there any way in django to distinguish if it is a normal browser request or ajax request

I am using django and making some ajax request to server. As the url is visible in javascript someone could easily copy that and start making request via url bar. Is there any way in django that we can distinguish that the coming request is sent by ajax not a regular browser reqeust.
You can use a tag in your ajax,and in code check request from
Yes you can use
HttpRequest.is_ajax()
as in documentation
https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.is_ajax

Update a Google Sheet Using HTTP Request in Postman

I have a server needing to update a shared Google Sheet. It generates special tokens for offline use so doesn't work with PHP quickstart module.
I am trying to setup request in Postman for this action:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update
But get the following result:
Is it possible to use HTTP for this API?
Turns out I had to add ?valueInputOption=RAW on the end of my URL request and removed valueInputOption from the request body JSON.
The valueInputOption should be passed as params to the POST URL, it should not be in the request body.
Also the sheetID and the range should be sent in the URL.
I suppose it should be a POST call not PUT.

Laravel 5.3 Returns 302 with Request Validation - Ajax Request

I am having trouble with an ajax request to a Laravel application, specifically making a POST request to an authentication controller. I'm sending a post request with SuperAgent to a controller that uses a Request class to validate the input. The request carries a password and a username. When I inspect the console I'm getting back a GET 200 OK and a POST 302 Not Found. I tried debugging the application routes but nothing seemed to work.
Turns out it was something very simple. Having used jquery for a long time to make ajax request, I overlooked a very important header. The 'Accept', 'application/json' Header. Debugging the Request validation, I noticed that Laravel's expectsJson method was returning false, so all I had to do was add said header to the SuperAgent request object.

send POST request with angularJS despite same-origin policy

Is there a way to send a POST request using AngularJS despite the same-origin policy?
I don't need to get the response from the request, I just need to send the request.
Just like creating a form and sending it to another server.
Thanks
You can use JSONP to send a request to another domain, however you can't use POST, it would have to be a GET request. Can you serialize your form values and send using GET?
http://docs.angularjs.org/api/ng.$http#jsonp
How to use type: "POST" in jsonp ajax call
Keep in mind that if you do use GET, you are limited with how much data you send, since URLs usually can't be over ~2000 characters.

how Ajax request is sent by browser

I want to ask you how the browser sends ajax request i mean what is the format of ajax request. So what is actual format of AJAX request sent by browser.
Thanks in advance
If you install Firefox and Firebug you can see for yourself:
http://codeclimber.net.nz/archive/2007/08/01/How-to-debug-XmlHttpRequest-with-Firebug.aspx
It's a standard HTTP request - just like any other request the browser makes.
You can read more about the XMLHttpRequest call and indeed the structure of a HTTP request on WikiPedia.
AJAX is shorthand for Asynchronous JavaScript and XML and does not define a standard on how the data is transferred.
Because the browsers are designed primarily as HTTP clients you should study GET and POST and maybe PUT and DELETE for RESTful web services.

Resources