Hi , I try to read through the ARRAY jQuery I was taking through JSON , but the response is " undefined" . How can I pass an array from routes to JQ ? The idea is to return the names of the images that arose through the array . Here's the code :
Route::post('upimage', function(){
$i = rand();
foreach (Input::file("image") as $image) {
$imagename = time(). $image->getClientOriginalName();
$upload = $image->move(public_path() . "/img/",$imagename);
$img_id = DB::table('images')->insert(
array('name' => $imagename, 'author' => '0')
);
if ($upload) {
$images [] = $imagename;
}
return Response::json($images);
});
}
jquery:
$("form#data").submit(function(event){
event.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
url: "upimage",
type: "POST",
data: formData,
success: function(data) {
$.each( data, function( key, value ) {
alert( key[ + ": " + value] );
});
},
cache: false,
contentType: false,
processData: false
});
});