您的位置:首页 > Web前端 > JavaScript

mvc 中 JSON,ajax

2017-08-14 14:23 253 查看
public JsonResult getimgsize()
{
var res = new JsonResult();
returnData products
4000
= new returnData();

products.uploadedSize = 0;

res.Data = products;
res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;//允许使用GET方式获取,否则用GET获取是会报错。
return res;
}
public byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}


view-----------------
var url = urls + 'Upimg03/getimgsize?ran=' + Math.random();
var uploadedSize = 0;
$.ajax({
url : url,
data: "fileName=" + file.name + "&lastModifiedDate=" + file.lastModifiedDate.getTime(),
async : false,
type : 'POST',
success: function (returnData) {

//returnData = JSON.parse(returnData);
// alert('服务器返回的尺寸'+returnData.uploadedSize);
uploadedSize = returnData.uploadedSize;
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: