文件使用jquery ajax上载到跨域WCF服务 [英] File Upload to a cross domain WCF service using jquery ajax
问题描述
以下是我要做的事情(不成功,我可能会补充),并希望您能给我任何方向
来自我的HTML5网站,我想要将文件上载到IIS 7.5中承载的跨域WCF服务。
除了上传文件外,我还需要向服务器上传功能发送附加参数
$ b这是可能的吗?
这是我的operationContract的样子:
Here is what I am trying to do (unsuccessfully, I might add) and would appreciate any direction you can give me
From my HTML5 site, I want to upload a file to a cross domain WCF service that is hosted in IIS 7.5.
In addition to uploading the files, I need to send additional parameters to the upload fucntion on the server
Is this possible to do?
Here is what my operationContract looks like:
[OperationContract]
[WebInvoke( Method = "POST",
UriTemplate = "/uploadmodeldata/?id={Id}&customerdatatype={customerdatatype}&data={data}")]
void UploadModelData(string Id, string customerdataType, byte[] data);
这是我的jquery ajax请求
Here is what my jquery ajax request
function FileVisits() {
var uid = checkCookie1();
userid = uid.toString().replace(/"/g, '''');
var fileData = JSON.stringify({
Id:userid ,customerdatatype:scanupload,
data: $(''#fileBinary'').val()
});
alert(fileData);
"use strict";
var wcfServiceUrl = "http://xxxxx:1337/Service1.svc/XMLService/";
$.ajax({
cache: false,
url: wcfServiceUrl + "uploadmodeldata/",
data: fileData,
type: "POST",
processData: false,
contentType: "application/json",
timeout: 10000,
dataType: "json",
headers: {
''User-agent'': ''Mozilla/5.0 (compatible) Greasemonkey'',
''Accept'': ''application/atom+xml,application/xml,text/xml'',
},
beforeSend: function (xhr) {
$.mobile.showPageLoadingMsg();
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
},
complete: function () {
$.mobile.hidePageLoadingMsg();
},
success: function (data) {
var result = data;
},
error: function (data) {
alert("Error");
}
});
}
如果文件大小小于100 kb,则发生此错误
>方法不允许
但如果文件大于100 kb则发生此错误
> 413请求实体大到
如何将文件从jquery ajax上传到跨域wcf。
谢谢
if file size is less then 100 kb this error occurred
> Method not allowed
but if file is greater then 100 kb this error occurred
> 413 Request entity to large
How can I upload a file from jquery ajax to cross domain wcf.
Thanks
推荐答案
(''#fileBinary'')。val()
});
alert(fileData);
use strict;
var wcfServiceUrl =http:// xxxxx:1337 / Service1.svc / XMLService /;
(''#fileBinary'').val() }); alert(fileData); "use strict"; var wcfServiceUrl = "http://xxxxx:1337/Service1.svc/XMLService/";
.ajax({
cache:false,
url:wcfServiceUrl +uploadmodeldata /,
data:fileData,
type:POST,
processData:false,
contentType:application / json,
超时:10000,
dataType:json,
标题:{
''用户代理'':''Mozilla / 5.0(兼容)Greasemonkey'',
''接受'':''application / atom + xml,application / xml,text / xml'',
},
beforeSend:function(xhr){
.ajax({ cache: false, url: wcfServiceUrl + "uploadmodeldata/", data: fileData, type: "POST", processData: false, contentType: "application/json", timeout: 10000, dataType: "json", headers: { ''User-agent'': ''Mozilla/5.0 (compatible) Greasemonkey'', ''Accept'': ''application/atom+xml,application/xml,text/xml'', }, beforeSend: function (xhr) {
.mobile.showPageLoadingMsg();
xhr.setRequestHeader(Content-type,application / x-www-form-urlencoded);
},
完成:function(){
.mobile.showPageLoadingMsg(); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); }, complete: function () {
这篇关于文件使用jquery ajax上载到跨域WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!