dpbdl44228 2018-09-05 08:02
浏览 60

如何将POST(javascript)发送到laravel刀片文件?

I made a webcam page in Laravel5.
I would like to send POST(javascript, WEBCAMjs) to crop.blade.php(laravel).

My code works well when run with only php.
   => form.setAttribute("action", "crop.php"); However, if I try to send it to laravel(crop.blade.php), it returns MethodNotAllowedHttpException.
   => form.setAttribute("action", "crop.blade.php");

How can I solve this problem?
thanks for your help in advance!

Webcam.snap( function(data_uri) {
        var obj1 = data_uri
        var form = document.createElement("form");
        form.setAttribute("charset", "UTF-8");
        form.setAttribute("method", "Post");
        #form.setAttribute("action", "crop.php");
        form.setAttribute("action", "crop.blade.php");
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", "raw");
        hiddenField.setAttribute("value", obj1);
        form.appendChild(hiddenField);

        var url ="crop"

        var status = "toolbar=no,directories=no,scrollbars=no,resizable=no,status=no,menubar=no,width=1240, height=1200, top=0,left=20"

        document.body.appendChild(form);
        form.submit();
}
  • 写回答

1条回答 默认 最新

  • douma5954 2018-09-05 08:07
    关注

    It will be the routing. If you go to your web.php file, you will see the route that you are loading for the page. It might look like the following:

    Route::get('crop', function () {
        return view('crop');
    });
    

    You also need the following to allow post requests

    Route::post('crop', function () {
        // Logic for the post request
    });
    

    Obviously it would be better to use controllers instead of closures, but that's the general idea.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。