Skip to content
Advertisement

Select2 is not selected when update a select field by ajax call

I am facing a problem when I use select2 class in select option. When I insert a form data using a field select2 class by ajax call then it is working properly

But when I update that select2 field by ajax calling same form firstly it is not selected value that I inserted first.

Note

ajax response is working properly

cdn, css and javascript integrated properly

I have tried below

Input Field

JavaScript

Javascript

JavaScript

Ajax Update

JavaScript

Advertisement

Answer

I was facing same problem few days ago. I have solved this issue from Select2 Documentation

JavaScript

Replace by this

JavaScript

And in your ajax request add new line

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement