简体   繁体   English

使用计数器和AJAX进行跨服务器下载的下载按钮

[英]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 我有一个用于提供文件跨服务器服务的PHP脚本: 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. 我认为最好的方法是使用JavaScript,但是在提供文件时遇到了麻烦。 So far I've only been able to output the response success: function(response) directly into the website (garbled text). 到目前为止,我只能将响应success: function(response)直接输出到网站(乱码)中。

My other code: http://pastebin.com/GAN5EDdb 我的其他代码: 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? 我是AJAX之类的新手,所以有更好的方法吗?

Please let me know. 请告诉我。

Thanks! 谢谢!

Tre 特雷

I believe the problem lies in you trying to send a php array directly to javascript. 我相信问题出在您试图将php数组直接发送到javascript上。 One way to accomplish this is converting the results into JSON format. 实现此目的的一种方法是将结果转换为JSON格式。

Try doing this: 尝试这样做:

PHP section: PHP部分:

return json_encode($res);

Javascript/JQuery section: Javascript / JQuery部分:

var javaArray = $.parseJSON(response);

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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