Laravel WebView中的Ajax文件上传不起作用

时间:2019-04-22 09:19:17

标签: php ajax laravel webview

我正在Webview中制作一个系统,用户可以更改其图像。

使用ajax,laravel,webview,但显示以下错误不起作用。                                                                                                                                                              profile_picture}}“ alt =”“ width =” 100“                                      高度=“ 100”                                      id =“ user_profile_img”>                                                          {{$ user-> name}}                             网站开发人员·设计师·团队负责人                             
                                                              上载个人资料图片                                                          保存                                              

<script type="text/javascript">

    $("#save_user_profile").click(function (event) {
        event.preventDefault();
        var authorizationToken = $("#authtoken").val();
        var form = document.forms.namedItem("user_profile_form"); // high importance!, here you need change "yourformname" with
        var formData = new FormData(form);


        $.ajax({
            headers: {
                'Authorization': authorizationToken,
                'device_type': 'android'
            },
            async: true,
            type: 'post',
            contentType: false,
            cache: false,

            url: '{{ action('Mobile\UserProfileController@updateUserProfile') }}',
            data: formData,
            processData: false,
            success: function (data) {
                var result = JSON.parse(data);

                if (result.status) {
                    alert(result.message);
                } else {
                    alert(result.message);
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
    });


    Android.pageParams("Profile", "", "", false, "", "", "");
</script>

这是我的控制器

public function updateUserProfile(Request $request)
    {

        $userimg = $request->file('user_profile_picture');
        echo json_encode(['status' => true, 'message' => $_FILES]);
    }

出现以下错误:

{"status":true,"message":{"user_profile_picture":{"name":"","type":"","tmp_name":"","error":4,"size":0}}}

请记住,我不在android webvier或ios webview或任何其他版本中打开的浏览器中使用它,但这将在webview中

1 个答案:

答案 0 :(得分:1)

更改

    $userimg = $request->file('user_profile_picture');
echo json_encode(['status' => true, 'message' => $userimg]);

}