這是我的職責,我在那裏張貼JSON只MVC4 AJAX後JSON
function test() {
var imgFile = document.getElementById('image');
// var imgData = JSON.stringify(getBase64Image(imgElem));
//var imgData = Convert.FormBase64String(imgElem);
$.ajax({
type: 'POST',
dataType: 'json',
url: "http://localhost:59102/Contacts/AddContact",
data: "json=" + "{\"token\":\"8mVm/nS1OfpU+nlQLbJjqXJ7kJI=VyLGI2GEKkGgtDt0babrAw==\"}",
success: function (returnPayload) {
console && console.log("request succeeded");
},
error: function (xhr, ajaxOptions, thrownError) {
console && console.log("request failed");
},
processData: false,
async: false
});
,我不知道如何添加到我的數據,圖像,我需要張貼JSON和圖像
這是我的控制器
[HttpPost]
[AllowAnonymous]
public JsonResult AddContact(string json, HttpPostedFileBase file)
{}
您還可以製作一個bew對象var newObject = {token:「your token」}並且只需添加圖像作爲屬性newObject.imageAsBAse64 =「base64StringHere」併發送整個對象。在服務器端,您只需提取所有內容 –