John Davidson

php - I'm having a weird problem with my Ajax code. How can I solve this?

0 comments
Message:



When I click on all of my edit buttons the first time then it populates into the city field and area field nicely. But when I clicked on the edit button a second time the city field does not populate. After refreshing its populate again with the same problem. I need help.


City field code:


<select class="form-control" id="selectCity">
<option value="0" selected disabled>--- Select City ---</option>
@foreach ($cities as $city)
<option value="{{ $city->id }}">{{ $city->city_name }}</option>
@endforeach
</select>

My Ajax code:


$(document).on('click', '#edit_area', function(e) {
e.preventDefault();
$('#addArea').hide();
$('#updateArea').show();
var area_id = $(this).val();

$.ajax({
type: "GET",
url: "/edit-area/" + area_id,
success: function(response) {
if (response.status == 400) {
//some staff goes here
} else {
$('#area_id').val(area_id);
$('#areaName').val(response.area[0].area_name);
$('#selectCity').find("option:contains(" + response.area[0].city_name + ")").attr('selected', 'selected');//this works more better
}
}
});
});


My Answer:
PHP is a popular server-side scripting language that is used to create dynamic web pages. It is often used in conjunction with HTML to add functionality to websites, such as processing form data, interacting with databases, and generating dynamic content. PHP stands for Hypertext Preprocessor, and it is open-source and free to use.

Rate this post

4 of 5 based on 4055 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us