I have submitted the json response from laravel controller but when it gives error the JQuery section is working fine but when the request succeeds the JQuery gives error that parase error and I am not able to read the data content but it shows the data in log console correctly.
JQuery Ajax code : ----------------------------
event.preventDefault();
url = $('a#sendpropertiesdata').attr('href');
data = new FormData($('#propertiescreateform')[0]);
$.ajax({
url: url,
type: "POST",
data: data,
processData: false,
dataType: 'json',
contentType: false,
beforeSend:function(){
},
success:function(data){
// alert(data.msg);
response = data
alert(response['code']);
if (data.code == 0 ){
$('span#error_message').text(data.error).css('color','red');
}else if (data.code == 1){
$('span#error_message').text(data.msg).css('color','green');
window.setTimeout(function(){
$('form#propertiescreateform').remove();
}, 3000);
}
},
complete: function(data, status ){
alert(data.code + " " + status );
if (data.code == 1 ){
$('span#error_message').text(data.msg).css('color','green');
window.setTimeout(function(){
$('form#propertiescreateform').remove();
}, 3000);
}
}
});
Controller Code -----------------------------------------------------------
$validator = \Validator::make($request -> all(), $rules);
if ($validator -> passes()){
$property = new Properties();
$property -> country = $request -> country ;
$property -> city = $request -> housecity ;
$property -> location = $request -> houseaddress ;
$property -> description = $request -> propertiesdescription ;
$property -> price = $request -> price;
$property -> save();
return response() -> json(['code' => 1, 'msg' => 'data saved successfully']);
}
}else {
return response() -> json(['code' => 0, 'error' => $validator -> errors()->all()]);
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3saUX4r
via IFTTT
Aucun commentaire:
Enregistrer un commentaire