Differentiating Between an AJAX Call / Browser Request

If you use Prototype, jQuery, Mootools or YUI you should find a X-Requested-With:XMLHttpRequest header which will do the trick for you. It should be possible to insert whatever header you like with other libraries. At the lowest level, given a XMLHttpRequest or XMLHTTP object, you can set this header with the setRequestHeader method as follows: … Read more

How to modify Cookie from Ajax call

The Cookie header is one of several which cannot be modified in an XMLHttpRequest. From the specification: Terminate [execution of the setRequestHeader method] if header is a case-insensitive match for one of the following headers: Accept-Charset Accept-Encoding Connection Content-Length Cookie Cookie2 Content-Transfer-Encoding Date Expect Host Keep-Alive Referer TE Trailer Transfer-Encoding Upgrade User-Agent Via … or … Read more

Intercept XMLHttpRequest and modify responseText

// // firefox, ie8+ // var accessor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, ‘responseText’); Object.defineProperty(XMLHttpRequest.prototype, ‘responseText’, { get: function() { console.log(‘get responseText’); return accessor.get.call(this); }, set: function(str) { console.log(‘set responseText: %s’, str); //return accessor.set.call(this, str); }, configurable: true }); // // chrome, safari (accessor == null) // var rawOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function() { if (!this._hooked) { this._hooked … Read more

Handle JSON Object in XMLHttp response in Excel VBA Code

The code gets the data from nseindia site which comes as a JSON string in responseDiv element. Required References 3 Class Module i have used cJSONScript cStringBuilder JSON (I have picked these class modules from here) You may download the file from this link Standard Module Const URl As String = “http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/GetQuote.jsp?symbol=ICICIBANK” Sub xmlHttp() Dim … Read more

Phantom JS synchronous AJAX request : NETWORK_ERR: XMLHttpRequest Exception 101

Try disabling the web security by using the command-line option –web-security=no when running your script. (phantomjs –web-security=no yourscript.js) From the PhantomJS reference (http://phantomjs.org/api/command-line.html): “–web-security=[true|false] enables web security and forbids cross-domain XHR (default is true). Also accepted: [yes|no]