I'm using a jquery plugin in my site. I want to validate a form first, Then send another data to controller,But doesn't through form. First validate is return a success feedback already. But when a second one is send, Doesn't have any feedback return. Here is my code
route.php
Route::controller('designs', 'DesignsController');
DesignsController.php
public function postTest() {
$validator = Validator::make(Input::all(), Design::$rules);
if ($validator->passes()) {
$response = array(
'status' => 'success'
);
return Response::json( $response );
}
$response = array(
'status' => 'fail'
);
return Response::json( $response );
}
public function postSaveimage() {
//Save Image complete return $success=1
if($success)
$response = array(
'status' => 'save image success'
);
else
$response = array(
'status' => 'Fail'
);
return Response::json( $response );
}
jquery
$('#design_form').on( 'submit' ,function() {
//Validate First form data
$.post(
$( this ).prop( 'action' ),
{
"_token": $( this ).find( 'input[name=_token]' ).val(),
"category_id": $( '#form_category_id' ).val(),
"title": $( '#form_title' ).val(),
"user_id": $( '#form_user_id' ).val(),
},
function( data ) {
//if validate fail
if(data.status=='fail')
{
alert('data.status');
}
//if validate pass
else
{
//Sent second data
$.post("designs/saveimage",
{
"_token": $( this ).find( 'input[name=_token]' ).val(),
'base64_image': yourDesigner.getProductDataURL()
}, function(data) {
if(data) {
alert(JSON.stringify(data));
}
else {
alert('fail!');
}
});
}
},
'json'
);
return false;
});