I have a link button on my page clicking on which, I download a file from some DMS system and then send the file after zipping it on server to the client using response.write.
But since the page is ajaxified, it throws an error.
Is possible to send a file to the client on a Ajax call?
I am using Telerik RadAjax.
Don't use Response.Write or Response.WriteFile to force file-download because that will simply not help in this context.
In order to do what you want, save the zipped file on disk and redirect the user to download-file. You can create a temp folder to hold the zipped files which you create on the fly and flush them every one hour or any such predefined time-interval. You need to call this from standard post-back driven non-ajaxed call. This will preserve the state.
Response.Redirect("path-file-to-download");
Response.End();
There is no reason to request the file with an AJAX callback, as downloading the file doesn't refresh the page and therefore the user doesn't lose the context, which is usually the reason why you would prefer AJAX callback.
According to your comments, there are 2 ways to overcome the problem :
You can write into the response stream at the same time that you are downloading the file from the second server and therefore making the progress visible in the open/save dialog of the browser.
You can temporarily store the file somewhere in the database / file system and send it with a second request made directly by the user.
The first one seems more reasonable to me as you don't have to deal with the intermediate storage.
You can send whatever data you like, you just have to be able to handle it in your JavaScript.
There isn't a great deal that JavaScript could do with a zipped file (unless you fancy finding, or writing, a zip decompression library in JavaScript).
Related
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.
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).
My understanding is that the AjaxFileUpload object uses an iframe to upload files. A postback occurs, but no other controls are posting back - at least that is what it looks like to me as I cannot access any other controls' data.
The purpose of the app is to allow the user to upload a file. It will then modify the contents of that file and save the results to the server. The problem is that it needs some extra information to make the modifications, and therefor needs the information that the user entered elsewhere on the page.
The only solution I have been able to come up with is to do a postback every time one of those other controls is modified, which affects the apps responsiveness. I have been looking for a couple of days for another solution.
Does anyone have any ideas? The best case solution would allow me to access all of the data I need when the AjaxFileUpload control does a postback.
you could have a ajax function that is reading changes from time to time external data, and update the information displayed, similar to email alerts, sorry for my English.
Goal:
I want to let my users download a file on my webpage. I want a new window to open and the file to be either displayed or downloaded there.
My implementation:
This file however, first has to be generated on the server-side, which might take a while. When the user clicks the button to download the file, I do an ajax call and show a waiting animation until I get a response. The controller action that handles the call will generate the file (PDF) and return a FileResult. Now in the succes function of my ajax call back in javascript, I get the file data.
Problem: I have no Idea what I'm supposed to do with this data to get it to the user.
Workaround:
Right now I use a workaround where I do not return the file in the ajax call, but store it in session. In the succes function I do window.open("/controller/getPDFFromSession") which will download the file. However, I prefer not to use the session for these kind of things.
Thanks in advance.
Problem: I have no Idea what I'm supposed to do with this data to get it to the user.
You shouldn't use AJAX for downloading files for this reason. You could do the following:
The user clicks on the download button
Using javascript you show some progress image informing him that he will have to wait
Using javascript you generate and inject a hidden iframe into the DOM having its src property pointing to the controller action supposed to generate the file
Once the iframe is loaded you could hide the progress image
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/