What should I add in data: and make it send the value of the message text field

<html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> </head> <body> <iframe name='chatWindow' id='chatWindow'frameborder="no" height="935" width="1910" src='iframe.php'>Chat</iframe> <br> <input type='text' id="text" name='message'> <input type='button' id="button" value="send"> <script> $(document).ready (function () { $("#button").bind("click", function (){ $.ajax ({ url: "iframe.php", type: "POST", data: ({}), dataType: "PHP" }); }); }); </script> </body> </html> 

    1 answer 1

    Your input 'a has id='text' , call it. Put its value in a variable up to $.ajax :

     var msg = $('#text').val(); $.ajax ({ ... data: msg, ... 

    Only in dataType is written the format in which the data will be sent to the server, in your case json :

     dataType: "json" 
    • it works, but why would I need to refresh the page to see the result ? - NoProgress
    • Naturally, you need to separately write code that will display the sent message. I advise you to read the documentation on jQuery jquery-docs.ru/ajax/jquery-ajax/#examples in more detail. - Klym