/    Sign up×
Community /Pin to ProfileBookmark

Return XLS data through AJAX

I have a PHP file that generates a spreadsheet and automatically downloads it.

Is there any way to be able to load this when a button is clicked on another page through AJAX?

My return data for the ajax call is a jumble of symbols.

Thanks.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@rnd_meNov 17.2009 — My return data for the ajax call is a jumble of symbols.[/QUOTE]

Isn't that what an excel file looks like when opened in notepad?

what do you want to happen?
Copy linkTweet thisAlerts:
@jelatinauthorNov 17.2009 — If I load the php script directly in the browser, it prompts the browser to download an XLS (spreadsheet) file.

If I call the script via AJAX, nothing happens, the response from the server is just a set of symbols. I want the AJAX to return the info and prompt the spreadsheet download.
Copy linkTweet thisAlerts:
@slaughtersNov 17.2009 — You can force your browser to think a web page is a XLS file by using the content type meta-tag
[code=html]<META HTTP-EQUIV='Content-Type' CONTENT='application/vnd.ms-excel'>[/code]

I expect the PHP file is doing something like this - ie dynamically generating a page that includes the meta tag (or just adds to the page header via a header("Content-Type: application/vnd.ms-excel"); ) so that when your browser sees it for the first time it looks like an XLS file to it.

I don't think you can modify the header to an already existing page - but you may be able to reassign the src of a hidden iframe to point to the new generated content.
Copy linkTweet thisAlerts:
@rnd_meNov 17.2009 — ajax traps it into a string; don't use ajax.

instead, simply point a hidden iframe's .src to the url, or send the url to window.open...

the long route is a binary ajax to dataURL conversion, but there's really no need fopr that here.
×

Success!

Help @jelatin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...