Ajax source from local file, will it decrease page load time? - ajax

I'm following this example with DataTables
https://datatables.net/examples/ajax/simple.html
Ajax loads data from a big txt file into the grid.
When visiting a static web page with this data, will the browser download the txt file completely - or only load what is needed?
Thank you!

Of course that will download the txt file completely and then it will (sort-filter-arrange data into pages etc) data to your datatable.
The ajax call in this case is not very useful indeed but sometimes is a lifesaver.

Related

Uploading a file stored in browser memory via ajax

Assume there are no cross-domain issues with the ajax calls to the server(s).
First, I am making an ajax call to grab the contents of a binary file (docx) from the server. The contents are then stored in the browser memory.
Next, I need to make another ajax call to the server to upload the file contents along with other form fields. The page may already contains the form, or the js can dynamically create the form (which would be hidden), or I can use the FormData object in the js code.
I can't figure out how to take file contents that are in memory and include them in a form POST call to upload the file along with the other form inputs. Any idea how to do this?
I thought perhaps using the FileReader object I could do this, as I have seen where you can use FileReader.readAsBinaryString() on a blob or binary data, then have the onloadend trigger the form submit.
I would prefer to use jquery, but that is not necessary.

How to scrape data from an ajax web page using R?

I would like to extract data from this web page using R:
I guess the web page is loaded via server using Ajax or something similar. Moreover I would like to save also the data available on the following pages, the ones that I can see when I press the NEXT button at the bottom of the data table.
Thanks a lot for any tips.
domenico
It appears to be generated using a JavaScript blob. You could look at rvest, which is an R library for just this problem (web scraping). If that doesn't work, RCUrl's GetURL function definitely grabs the script contents (although it's ugly as sin and you'll be wanting to grep it. Mind you, all automatically generated HTML is ugly).

Getting the JSON file when triggering AJAX

I'm writing a crawler to get the content from a website which uses AJAX.
There is a "show more" button at the bottom of the page, and my origin approach is to use Selenium.PhantomJS to pretend a web browser but it works in some website and some don't.
I'm wondering if there is some way i can directly get the underly JSON file of the AJAX action. Please give me some details, thanks.
By the way, I'm using Python.
I understand this is less of a python than a scraping problem in general (and I understand you meant "scraping" instead of "crawling" as a scraper reads/parses/processes one page whereas a crawler processes multiple pages and they're relation to each other).
You can get the JSON file immediately given you know it's URL. If you don't (for example because the URL changes from time to time), you might need to search through javascript files on the page manually to find out how the URL is generated.
Once you know the JSON file's URL, it's quite simple. As you already seem to know how to get the HTML of the "main" page, you can use your existing code to get the JSON file.
I'm not familiar with PhantomJS, but I reckon it's easier to get the JSON file immediately instead of simulating an AJAX request (if that's even possible with Phantom).

HTML 5 Web Storage - Local/server communication

I need load localStorage data right on my homepage. But when the page loads, the PHP/SQL instructions are already processed.
There's a way to process it before the server interation and use the localStorage data in my SQL instructions?
ps. I tried AJAX, loading my homepage in a DIV inside an index page... but it didn't work.
The answer is no - you can't read the LocalStorage data on the first load of your web site. However, you can use Ajax to hit your server and send a copy of any LocalStorage value to your server. You mentioned using ajax to load your homepage in a div. That should work, if you pass along the LocalStorage information in the url. So for example, imagine you have a localstorage key called name. If you want to load the contents of foo.php into a div and have PHP get access to name, you would pass it in the URL: "foo.php?name="+escape(localstorage.name)". You can also use a Form post too.

import from file in javascript

I have a html/javascript table/grid that I need to import data from a file, this is not possible without serverside. So I decides to have a FileEcho server that takes a file upload from the table/grid, the problem is I don't want to refresh the page afterwards, it's a multipart request, not an ajax request. Is it possible to up the file ajax style?
how can this be done? any solution to my problem?
A popular way is to do the file upload in an iframe (you can set the <form>'s target attribute to the name attribute of your iframe)
You can attach an onload event on the iframe to find out when the data has been echoed from the server. From there, you can grab the contentDocument attribute from the iframe object in javascript (from there you could look at the innerHTML content of the contentDocument.body to see the data).
Just note that in IE, you have to use document.frames['frame_name'].document instead of iframeObject.contentDocument
See these articles for more info:
http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
http://www.openjs.com/articles/ajax/ajax_file_upload/

Resources