HTTP Cookies and Ajax requests over HTTPS

Ok, found the solution to the cookie problem. See XHR specs, jQuery docs and StackOverflow. The solution to have the cookies sent when switching protocol and/or subdomain is to set the withCredentials property to true. E.g. (using jQuery) $.ajax( { /* Setup the call */ xhrFields: { withCredentials: true } });

How do I POST an array of objects with $.ajax (jQuery or Zepto)

Be sure to stringify before sending. I leaned on the libraries too much and thought they would encode properly based on the contentType I was posting, but they do not seem to. Works: $.ajax({ url: _saveAllDevicesUrl , type: ‘POST’ , contentType: ‘application/json’ , data: JSON.stringify(postData) //stringify is important , success: _madeSave.bind(this) }); I prefer this … Read more

List of events

You might want to look at “JavaScript HTML DOM Events” for a general overview of events: http://www.w3schools.com/jsref/dom_obj_event.asp PrimeFaces is built on jQuery, so here’s jQuery’s “Events” documentation: http://api.jquery.com/category/events/ http://api.jquery.com/category/events/form-events/ http://api.jquery.com/category/events/keyboard-events/ http://api.jquery.com/category/events/mouse-events/ http://api.jquery.com/category/events/browser-events/ Below, I’ve listed some of the more common events, with comments about where they can be used (taken from jQuery documentation). Mouse Events … Read more

Drag-and-drop file upload in Google Chrome/Chromium and Safari?

WARNING: This is compatibility code for very old versions of Safari and Chrome. Modern browsers all support the FileReader API; here’s one tutorial: https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications This code is now only useful if for some reason you have a need to support Safari 5 and older, or Chrome 6 and older. One possibility is to use the … Read more

How to Set Selected value in Multi-Value Select in Jquery-Select2.?

Well actually your only need $.each to get all values, it will help you jsfiddle.net/NdQbw/5 <div class=”divright”> <select id=”drp_Books_Ill_Illustrations” class=”leaderMultiSelctdropdown Books_Illustrations” name=”drp_Books_Ill_Illustrations” multiple=””> <option value=” “>No illustrations</option> <option value=”a” selected>Illustrations</option> <option value=”b”>Maps</option> <option value=”c” selected>selectedPortraits</option> </select> </div> <div class=”divright”> <select id=”drp_Books_Ill_Illustrations1″ class=” Books_Illustrations” name=”drp_Books_Ill_Illustrations” multiple=””> <option value=” “>No illustrations</option> <option value=”a”>Illustrations</option> <option value=”b”>Maps</option> <option value=”c”>selectedPortraits</option> … Read more

Javascript: How to read a hand held barcode scanner best?

Your pseudo code won’t work, because you don’t have access to the scanner to catch events like scanButtonDown. Your only option is a HID scanner, which behaves exactly like a keyboard. To differentiate scanner input from keyboard input you have two options: Timer-based or prefix-based. Timer-based The scanner is likely to input characters much quicker … Read more

how to use jQuery ajax calls with node.js

If your simple test page is located on other protocol/domain/port than your hello world node.js example you are doing cross-domain requests and violating same origin policy therefore your jQuery ajax calls (get and load) are failing silently. To get this working cross-domain you should use JSONP based format. For example node.js code: var http = … Read more