0
I need to assemble a form (blade
) where I glue an image, I use javascript
and it works without problems, but when I try to recover this image in controller
, the data are not passed.
In the HTML
am using CANVAS
:
<canvas class="imagem" id='imagem' width="1200" height="400" id="canvas"></canvas>
In Javascript when I try to save:
<script>
<!--
function exportCanvas(form){
var canvas = document.getElementById('imagem');
var dataURL = canvas.toDataURL();
alert(dataURL);
$.ajax({
type: "POST",
url: "/imagem",
data: {
imgBase64: dataURL
}
}).done(function(o) {
console.log('saved');
// Do here whatever you want.
});
//form.submit;
}
-->
</script>
In my controller
:
$data = $request->imgBase64;
but the variable $data
presents value null.
How’s your controller code?
– Victor Carnaval
<?php namespace App Http Controllers; use Illuminate Support Facades Auth; use Illuminate Http Request; use Illuminate Support Facades URL; use Illuminate Support Facades DB; class Imagemcontroller extends Controller { public Function index(Request $request) { Return view('image.image'); } public Function Edit(Request $request) { // $capture = $request->capture; $data = $request->imgBase64; // $image = Image::make($request->get('imgBase64')); var_dump($data); } Return '; }
– Reinaldo M. Okano
The code in the controller is pretty simple, just so I can check if the data has been passed.
– Reinaldo M. Okano
What happens when you display the request content? Example:
var_dump($request->all());
– Victor Carnaval
When I run a var_dump() the value it shows on the screen is null.
– Reinaldo M. Okano
Strange... try to change the method
ajax
for$.post('/imagem', { imgBase64: dataURL });
– Victor Carnaval