Py学习  »  Jquery

如何通过web api上传a文件(图片)并用jquery更新数据?

Dave • 6 年前 • 1832 次点击  

我正在尝试通过web api将一个图像作为化身照片上传到服务器。

任何人都可以解释如何通过当前用户id has token将图像url插入到数据中?

我已经做了 $.getJSON (url,... 我可以在任何地方阅读和附加它们。

我有这样的东西:

用户ID=1

/API/图像/上传表单/化身

/API/用户/更新用户信息

一。如何使用jquery附加图像文件并通过web api发布?

2.我怎样才能重新上传(更新)文件?

 $(document).ready(function (e) {
     $('#upload').on('click', function () {
     var file_data = $('#file').prop('files')[0];
     var form_data = new FormData();
     form_data.append('file', file_data);
     $.ajax({
             url: 'https://myurl/api/images/upload_form/avatar', // point to server-side controller method
             dataType: 'text', // what to expect back from the server
             cache: false,
             contentType: false,
             processData: false,
             data: form_data,
             type: 'post',
             success: function (response) {
                 $('#msg').html(response); // display success response from the server
                 },
             error: function (response) {
                 $('#msg').html(response); // display error response from the server
                 }
           });
     });
});

用户id=1<<我需要将此键和值添加到post url,但如何添加?

任何帮助都将不胜感激。

谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/46742
文章 [ 1 ]  |  最新文章 6 年前