Help me figure it out, using jquery, insert it into the select option, but in the source code there is no option. In the browser option are added and displayed. And since they are not in the source code, the form flies away empty when sent to the server. How much do I understand correctly that without a reboot is not enough? that is, when the DOM is already lined up then no longer change it? But how can I solve the problem?

Code itself

$.get('/getcitys?city_id=' + city_id, function(data){ $.each(data, function(index, subcatObj){ $('#citys').append('<option value="'+subcatObj.id+'">'+ subcatObj.city +'</option>'); }); }); 

    1 answer 1

    The fact is that you are confusing the place where you need to watch the added through append() . If you look at the source code of the page, in any browser, then there really will be the code that the web server gave away, and nothing more - this is what the browser receives at the entrance and after that it starts to execute.

    To see what the browser will eventually compile, you need to look at the inspector, in the case of Chrome, it is invoked either from the Просмотреть код context menu or via F12 . Similarly in other browsers. This is where you will see the DOM model generated by the browser and your scripts.

    The empty form flies away for sure due to an error in the code processing its filling and sending.

    • Stanislav thanks for the clarification! but it has already begun to think that it is not logical to get. Now I'll take a look at the code. I can understand where the error is. - jaans
    • @jaans is not a question, and feel free to mark the answer as correct;) If you have questions about the code, create another, separate question, already with a description of the specific submission code, form and all that. - Stanislav Belichenko
    • I looked in Firefox Develop and everything is correct in the Inspector tab, the browser really generates everything correctly. See why it is not sent to the server. - jaans
    • one
      Thanks again all found a mistake. Everything is working. - jaans