Use AJAX to send html5 textarea directly without html <form>

后端 未结 3 2022
梦如初夏
梦如初夏 2020-12-17 03:11

Recently I am confused about whether it\'s possible to send input/textarea data directly without being included in html

. I thought in web page, if
3条回答
  •  無奈伤痛
    2020-12-17 03:21

    Ajax (Asynchronous Javascript & XML) is a way to send data from client to the server asynchronously. For that you'd have to write code for sending the data in the client-side using Javascript/HTML and also to process the received data using server-side languages (eg PHP) on the server-side.

    And, yes you don't need a tag to do so.

    Check out this example.

    HTML:

    
    
    
    
    

    Javascript:

    $('#submit').click(function(e) {
        e.preventDefault();
    
        // information to be sent to the server
        var info = $('#foo').val();
    
        $.ajax({
            type: "POST",
            url: 'server.php',
            data: {foo: info}
        });
    });
    

    Server-side Handler (PHP): server.php

    See this for your reference http://api.jquery.com/jquery.ajax/

提交回复
热议问题