简体   繁体   中英

Download button for cross-server download with counter & AJAX

I have a little PHP script that is used to serve a file cross-server : http://pastebin.com/Z1xhPxVm

This works perfectly well.

Now, what I'm trying to accomplish is to serve this file via a button click. I figure the best way to do this is to use JavaScript but have been having trouble serving the file. So far I've only been able to output the response success: function(response) directly into the website (garbled text).

My other code: http://pastebin.com/GAN5EDdb

and I added:

if ( $_POST['dl'] == true ) {
        return sendTest();
}

To the top of the first code I pasted.

I'm kind of new to AJAX and the like, so is there a better way to do this?

Please let me know.

Thanks!

Tre

I believe the problem lies in you trying to send a php array directly to javascript. One way to accomplish this is converting the results into JSON format.

Try doing this:

PHP section:

return json_encode($res);

Javascript/JQuery section:

var javaArray = $.parseJSON(response);

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM