Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var store = window.localStorage,
- request = {
- url: {SERVER_URL},
- type: "GET",
- dataType: 'json',
- cache: false,
- headers : {
- Cookie: store.getItem('session')
- },
- complete: function (jqXHR, status){
- if (status != 'success') {
- console.log('ajax status: failure');
- } else if (store.getItem('session') != null) {
- console.log('ajax status: session exists');
- } else {
- console.log('ajax status: saving cookie');
- var header = jqXHR.getAllResponseHeaders();
- var match = header.match(/(Set-Cookie|set-cookie): (.+?);/);
- if (match) {
- session = match[2];
- store.setItem("session", session);
- }
- }
- },
- success: function (response){
- if (typeof response != 'object') {
- console.log('ajax status: no response object');
- return;
- } else {
- console.log('ajax status: responding with object');
- // Do response actions here...
- }
- }
- }
- $.ajax(request);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement