You get up in a stupor from a simple task, how do you make sure that when you click on a div, the relevant information is immediately displayed? and is the data variable needed in this case?

<div id="Mram" class="stone">Мрамор</div> <div id="Gran" class="stone">Гранит</div> <div id="MramMoz" class="stone">Мраморная мозайка</div> <div id="DragKam" class="stone">Полудрагоценные камни</div> <div id="Omiks" class="stone">Оникс</div> <div class="col-xs-12 col-md-9" id="kamen"></div> <script> $(document).ready(function(){ $("#Mram").on("click", function(){ $.ajax({ url: "Mram.html", type: "POST", data: , success: function(data){ $("#kamen").html(data); } }); }); }); </script> 
  • What kind of information should be displayed and where will it come from? Be specific. - Daniel Protopopov
  • @DanielProtopopov in Mram.html file like this. <h2> Marble </ h2> <p class = "lead"> At all times, marble products were a symbol of the refined taste of their owner. The formation of marble occurs under the pressure of layers and exposure to high temperatures, reaching up to 1000 ° C, marble crystals acquire various shapes and sizes. </ P> - Ruslan
  • It should appear in id = "kamen" in this diva. That is, when you click on id = "Mram", the information should be displayed in the diva with id = "kamen" - Ruslan
  • I just had a question what to write in data is necessary in this case - Ruslan

3 answers 3

  $("#Mram").on("click", function(){ $.ajax({ url: "://home/nonick/text.html?callback", type: "POST", data: {}, success: function(data){ $("#kamen").html(data); } }); }); 

in this example, data can be left blank.

    If the code in the HTML file is static and it is located on the same domain, then like this:

     $.get( "Mram.html", function( data ) { $( "#kamen" ).html( data ); } 
    • +1 no POST, but here it is not necessary - Igor

    In data - and this is not a variable, by the way, but an object property - you transmit some data in the same way as you would transfer it, simply by sending a POST request. For example, a form. If, in this particular example, what the server gives to your question depends on any input data, then the answer is yes, it’s necessary. If the server in any case gives the same answer, then in the data nothing to transfer does not make sense.

    In general, data needed, for example, when registering a user, when you transfer the username and password you entered to the server, maybe some other data. In this case, judging from the question posed, you do not need it.

    And yes, if you don’t transfer anything to the server, it’s better to pass an empty object {} .