0

私は、html エディターとして niceEdit を使用し、バックエンドには mysql を使用しています。AJAXを使用してphpにデータを送信するプロセス。

私のhtmlコードは次のとおりです。

<div class='atabcontent'>
    <form id='apostform' method='POST'>
        <input name='request' type='hidden' value='atabaddnew' />
        <textarea id='aposttextarea' name='area1' style='width:780px; height: 400px; margin: 10px auto 0 auto;'cols='40'></textarea>
    <div style='height: 5px;'></div>
    <button id='apostsubmit'>Save</button>
    </form>
</div>

ここに ajax コードがあります。

$("#apostform").submit( function () { 
    //add a loading bar first
    $('div.atabcontent').append("<img class='loading' src='media/loading.gif' />");
    //send data to processor.php
    $.post(
        'processor.php',
        $(this).serialize(),
        //here, where we're going to manage the respond from the processor.php
        function(data){
            //remove the loading bar
            $('.atabcontent img.loading').remove();
            //output the respond
            $('div.atabcontent').html(data).show();
        });
    return false;   
});

php ファイル (processor.php) を次に示します。

<? //this a processor e.g. post, delete, edit etc..
    //check if a post "request" is present..
    if (isset($_POST['request']))
    {
        //check if what type of request, if request type is equal to atabmenu then..
        if ($_POST['request'] === "atabmenu")
        {
            echo $_POST['data'];
        }
        elseif ($_POST['request'] === "atabaddnew")
        {
            echo htmlspecialchars($_POST['area1']);
        }
        //end
        //else if no request then go to fail.php along with the error code of "unable to     process the data"
    }
    else
    {
        header("location: fail.php?error=unable to process the data");
    }

?>

上記のコードでわかるように、正常に動作するはずですが、ajax 応答ハンドラーによってフェッチされた php ファイルからの応答は空であり、送信されたデータがないか、どちらも受信されていないようです。これを試した

$("#apostform").submit( function () { 
    var data = $('#apostform textarea').val();

    alert (data);
    return false;   
});

しかし、alertbox の内容は空で、コードでわかるように、"#apostform" の値でボックスに警告する必要があります。私は通常のフォームを試しました。つまり、フォームから受信したデータを表示するため、データが受信されたことがわかるため、ajax はなく、正常に動作します。

誰かがこれに関する問題と思われるものを指摘するのを手伝ってくれることを願っています. とにかく私はniceEditテキストボックスhttp://nicedit.com/を使用します

PS: 私はどんな提案、推薦、アイデアでも開いています。前もって感謝します。

4

1 に答える 1

1

送信機能にいくつかの構文エラーがあるようです

$("#apostform").submit( function () { 
    var data = $('#apostform textarea').val(); // missing equals sign and closing apostrophe

    alert (data);
    return false;   
});
于 2012-08-06T07:30:44.203 に答える