JavaScript AJAX Request Library for Browsers that Supports Cookies - ajax

I am looking for a JavaScript AJAX request library for browsers that also supports cookies. I tried broswer-request but apparently it does not support cookies.
Any suggestions?
It is also better if it is available for NodeJS through NPM for server side.
Regards

I suggest jQuery's functions $.post, $.get, and $.ajax for the ajax requests. You can also edit cookies with jQuery, if you use this plugin.
StackOverFlow Post
Link to file

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

Getting the URL from the ajax response using EmberJS

Can anyone help me in how to get the url, from the Ajax response in Ember.
This is to handle a specific use case in which server redirects to another url and returns data from the new url(302 redirect).
If i am able to get the url form the response, then i can check if the requested url is different from the response url and can take the action accordingly.
Note: If we use Angular (tried with Angular4), then we can get the response details including url and header from the response, if you use Http service from '#angular/http'
I am using following config for EmberJS
-ember-cli: 2.14.2
-node: 8.1.0
-os: darwin x64
In comment you specified that you fetch the record using Ember.$.ajax. Ember.$ is not more than an alias for jQuery. So Ember.$.ajax is the same as jQuery.ajax. Following jQuery.ajax documentation success function is called with jqXHR object as third argument. This is a superset of browsers native XMLHttpRequest object. XMLHttpRequest object provides a read-only property responseURL which is what you are looking for.
In general I would recommend to not use jQuery.ajax in modern ember application. There are two great alternatives:
ember-fetch provides a HTML5 fetch polyfill from github wrapped and bundled for ember-cli.
ember-ajax provides a service for making AJAX requests which provides RSVP promises.
There is also work ongoing to migrate away from jQuery.ajax in ember-data.

AJAX client tool for interrogating endpoints

Are there any AJAX client tools for interrogating ajax endpoints?
I am using firebug for development and have installed some addons for manipulating the request headers.
However, I am finding this to be quite unproductive as I need to set the X-Requested-With in the header whenever I want to test my AJAX endpoint and then remove it for testing my pages normally.
I am looking for a GUI tool which allows me to point it to an AJAX endpoint and craft a request, be it a JSON request or just a standard GET/POST request.
Something equivalent to Pinta (for testing AMF requests) in the AJAX world would be nice.
Do any tools like this exist?
I just found HttpRequest (a FireFox addon) that can do this. Simply just set the request header x-requested-with to XMLHttpRequest and away you go!

will the webserver [IIS] possibly know whether a request is an AJAX request or a Normal one

will any webserver [IIS possibly] know whether a request is an AJAX request or a Normal one.
If you are using native XmlHttpRequests then there is no difference between this request and once generated by visiting a page or submitting a form. If you use jQuery to create the AJAX request then is adds a request header X-Requested-With: XMLHttpRequest. This header could be used to distinguish AJAX and non-AJAX requests.
Some (most?) frameworks can send a custom header, but, really, an ajax request is just the same as a "normal" request from the point of view of the server.
If you use curl, wget, telnet, or a program you write yourself, then the web server handles the request the same way - at the end of the day, it's all HTTP.
The easiest way for the receiving page to 'know' would be to send a query string parameter. This isn't 100% safe though.
Firebug can show you what is being sent to the server from both types of requests, try it out.
Possibly, it is not the webserver that can distinguish, but the server side code might be able to distinguish. If you are talking about ASP.NET and AJAX, then ScriptManager.IsInAsyncPostBack can be used to find whether a postback is from AJAX or not.

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