Ajax vs Socket.io

Many of the generic tradeoffs between webSocket and Ajax are discussed here: websocket vs rest API for real time data? Some tradeoff issues for mobile devices are discussed here: Cordova: Sockets, PushNotifications, or repeatedly polling server? In a nutshell, if your data is primarily server-driven and then needs to be sent out to clients and … Read more

Google Maps API throws “Uncaught ReferenceError: google is not defined” only when using AJAX

The API can’t be loaded after the document has finished loading by default, you’ll need to load it asynchronous. modify the page with the map: <div id=”map_canvas” style=”height: 354px; width:713px;”></div> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js”></script> <script src=”https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=initialize”></script> <script> var directionsDisplay, directionsService, map; function initialize() { var directionsService = new google.maps.DirectionsService(); directionsDisplay = new google.maps.DirectionsRenderer(); var chicago = new … Read more

jQuery send string as POST parameters

Try like this: $.ajax({ type: ‘POST’, // make sure you respect the same origin policy with this url: // http://en.wikipedia.org/wiki/Same_origin_policy url: ‘http://nakolesah.ru/’, data: { ‘foo’: ‘bar’, ‘ca$libri’: ‘no$libri’ // <– the $ sign in the parameter name seems unusual, I would avoid it }, success: function(msg){ alert(‘wow’ + msg); } });

GET vs POST in Ajax

GET is designed for getting data from the server. POST (and lesser-known friends PUT and DELETE) are designed for modifying data on the server. A GET request should never cause data to be removed from an application. If you have a link you can click on with a GET to remove data, then Google spidering … Read more

How do you scrape AJAX pages?

Overview: All screen scraping first requires manual review of the page you want to extract resources from. When dealing with AJAX you usually just need to analyze a bit more than just simply the HTML. When dealing with AJAX this just means that the value you want is not in the initial HTML document that … Read more

MVC Return Partial View as JSON

You can extract the html string from the PartialViewResult object, similar to the answer to this thread: Render a view as a string PartialViewResult and ViewResult both derive from ViewResultBase, so the same method should work on both. Using the code from the thread above, you would be able to use: public ActionResult ReturnSpecialJsonIfInvalid(AwesomenessModel model) … Read more

WebSockets protocol vs HTTP

1) Why is the WebSockets protocol better? WebSockets is better for situations that involve low-latency communication especially for low latency for client to server messages. For server to client data you can get fairly low latency using long-held connections and chunked transfer. However, this doesn’t help with client to server latency which requires a new … Read more