jQuery的AJAX后与文件上传 [英] jQuery AJAX post with fileupload
问题描述
我有一个功能页面传送数据到页面的WebMethod
I have a functional page posting data to a Page WebMethod
[WebMethod()]
public static string sayHello(string pTest, string pText)
{
return pTest + " - " + pText;
}
我称之为使用这个jQuery
which I call using this jQuery
$(document).ready(function () {
$("#sayHelloButton").click(function (event) {
var name = $('#name').val();
var text = $('#text').val();
var dataString = JSON.stringify({
pTest: name,
pText: text
});
$.ajax({
type: "POST",
url: "page.aspx/sayHello",
contentType: "application/json; charset=utf-8",
data: dataString,
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed,
beforeSend: AjaxStart,
complete: AjaxEnd
});
});
});
但现在它也应该可以上传一个文件,我在这里有点丢失。
but now it should also be possible to upload a file and here I am a bit lost.
从我可以在不同的岗位读这是不可能的,但请纠正我,如果我错了 - 但我已经看到一些jQuery插件这使得上传实现的,如通过Flash的脚本,但如何将它,然后才有可能既POST数据并上传只有一个点击?有没有人有这上传插件是最好的任何建议 - ?以及如何我可以在上传后在一个动作中获得成功。
From what I can read in different posts in here it is not possible but please correct me if I am wrong - but I have seen several jQuery plugins which make upload possible, e.g. through a Flash-script, but how will it then be possible to both post data and upload with only one click? Does anyone have any suggestions which upload plugin is best - and how i can succeed in upload and post in one action?
推荐答案
不能告诉所有的插件,但我使用jQuery的形式没有任何问题。没有闪光灯参与,它只是创建隐藏的iframe来代替。
Can't tell for all plugins, but I'm using jQuery Form without any problems. No flash involved, it just creates hidden iframe instead.
但如何将它,然后才有可能既POST数据并上传,只有点击的
的过程是相同的,与正常Ajax请求。您声明表单元素,但不是 $('#MyForm的)提交();
DO $('#MyForm的')ajaxSubmit会()
。
but how will it then be possible to both post data and upload with only one click
The process is the same as with normal ajax request. You declare a form element, but instead of $('#myform').submit();
do $('#myform').ajaxSubmit()
.
这篇关于jQuery的AJAX后与文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!