Old input not working when using AJAX drop down dependent list
When I using AJAX to populate dependent drop down list and some field in form get error on validate, Laravel return back to page but value at my dependent drop down list it can't to passing old value. This is my code:
This parent dropdown to populate child dropdown, this old input working fine:
You are using ajax, you have to display the errors:
error: function (data, ajaxOptions, thrownError) {
var status = data.status;
//alert(status);
if (data.status === 422) {
$.each(data.responseJSON.errors, function (key, value) {
$('#msg').append('<div>' + value + '</div>');
});
}
Thank you, i'm not to show the error because Laravel have do with validate. My concern is why old input is not working to my child drop down list. I have try jquery to set selected value but not working like :
var oldvalue= "{{ old('state') }}";
$("#state select").val(oldvalue);
Simply don't redirect back if you're using ajax and all inputs will remain. Use the ajax callback to populate errors and what not from the validation.
You may need a preventDefault() on the button submit handler to prevent the page from refreshing.
That's why I mentioned take some Ajax JavaScript tutorials to get a better understanding.
in Ajax you return a response , it's not using session. There is no old data.