Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AJAX将数据传递给PHP_Javascript_Html_Ajax - Fatal编程技术网

Javascript AJAX将数据传递给PHP

Javascript AJAX将数据传递给PHP,javascript,html,ajax,Javascript,Html,Ajax,我一直在搜索这个论坛,但没有得到好的结果。我有这个HTML: <form method="post" id="postform"> <input type="text" name="message" id="message" placeholder='Say "Hello!"' class="mymessage" maxlength="255"/> <br /> <input id="submit

我一直在搜索这个论坛,但没有得到好的结果。我有这个HTML:

<form method="post" id="postform">
          <input type="text" name="message" id="message" placeholder='Say "Hello!"' class="mymessage" maxlength="255"/>
          <br />
         <input id="submit" type="button" value="Send"/>
        </form>
我需要在不刷新页面的情况下将消息内容传递给PHP。这是我做的,但不起作用。

检查语法:

  • 用引号将
    url
    括起来。
  • 删除
    'message'
    变量周围的单引号

    $.ajax({
        url:  'post.php',
        type: 'POST',
        data: {message : message}   
    }).done(function( msg ) {
        alert( "Data Saved: " + msg );
    });
    
  • 请参阅其文档页面底部的第一个示例。

    检查语法:

  • 用引号将
    url
    括起来。
  • 删除
    'message'
    变量周围的单引号

    $.ajax({
        url:  'post.php',
        type: 'POST',
        data: {message : message}   
    }).done(function( msg ) {
        alert( "Data Saved: " + msg );
    });
    
  • 请参见其文档页面底部的第一个示例

    我需要在不刷新页面的情况下将消息内容传递给PHP

    改为处理表单提交:

    $("#postform").submit(function(){
        var message = $('#message').val();
        $.ajax({
           url: 'post.php',
           type:'POST',
           data: {message:message}   
        }).done(function( data) { 
            // handle response from the server in case of success.
        });
    
       return false; //to prevent submitting and refreshing the page.
    });
    
    我需要在不刷新页面的情况下将消息内容传递给PHP

    改为处理表单提交:

    $("#postform").submit(function(){
        var message = $('#message').val();
        $.ajax({
           url: 'post.php',
           type:'POST',
           data: {message:message}   
        }).done(function( data) { 
            // handle response from the server in case of success.
        });
    
       return false; //to prevent submitting and refreshing the page.
    });