【发布时间】:2014-05-26 17:41:48
【问题描述】:
您好,我正在尝试在基于 java 的自定义服务器之间传输文件。服务器使用输出流来发送和接收文件,它接受一个字节数组。有没有类似的方法用 jquery 将文件拆分成字节数组并在 php 脚本中通过 TCP 套接字发送?
谢谢!
【问题讨论】:
您好,我正在尝试在基于 java 的自定义服务器之间传输文件。服务器使用输出流来发送和接收文件,它接受一个字节数组。有没有类似的方法用 jquery 将文件拆分成字节数组并在 php 脚本中通过 TCP 套接字发送?
谢谢!
【问题讨论】:
使用jQuery Ajax File Upload plugin。它对我有用!
function ajaxFileUpload()
{
//starting setting some animation when the ajax starts and completes
$("#loading")
.ajaxStart(function(){
$(this).show();
})
.ajaxComplete(function(){
$(this).hide();
});
/*
prepareing ajax file upload
url: the url of script file handling the uploaded files
fileElementId: the file type of input element id and it will be the index of $_FILES Array()
dataType: it support json, xml
secureuri:use secure protocol
success: call back function when the ajax complete
error: callback function when the ajax failed
*/
$.ajaxFileUpload
(
{
url:'doajaxfileupload.php',
secureuri:false,
fileElementId:'fileToUpload',
dataType: 'json',
success: function (data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error != '')
{
alert(data.error);
}else
{
alert(data.msg);
}
}
},
error: function (data, status, e)
{
alert(e);
}
}
)
return false;
}
【讨论】: