weixin_33738578 2014-03-13 09:14 采纳率: 0%
浏览 22

MVC4 AJAX发布JSON

this is my function, where i post json only

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
            });

and i dont know how to add to my data, image, i need to post json and image

this is my controller

[HttpPost]
        [AllowAnonymous]
        public JsonResult AddContact(string json, HttpPostedFileBase file)
        {}
  • 写回答

2条回答 默认 最新

  • weixin_33725515 2014-03-13 09:27
    关注

    You can't upload files via AJAX (by design) unless you use a plugin that utilises other 'technology' such as flash, or iframes - this is a security measure as JavaScript reading local files on your machine would not be the best idea

    There's an option here: http://jquery.malsup.com/form/

    ...otherwise I suggest looking up one of the many other alternatives!

    评论

报告相同问题?

悬赏问题

  • ¥20 python忆阻器数字识别
  • ¥15 无法输出helloworld
  • ¥15 高通uboot 打印ubi init err 22
  • ¥20 PDF元数据中的XMP媒体管理属性
  • ¥15 R语言中lasso回归报错
  • ¥15 网站突然不能访问了,上午还好好的
  • ¥15 有没有dl可以帮弄”我去图书馆”秒选道具和积分
  • ¥15 semrush,SEO,内嵌网站,api
  • ¥15 Stata:为什么reghdfe后的因变量没有被发现识别啊
  • ¥15 振荡电路,ADS仿真