4

私のcore.jsファイルにajaxハッシュURLが関係していると確信しています。しかし、フォームを送信しようとしていますが、希望どおりに送信されません。これは core.js ファイルです。

// call init
$(init);


function init() {
    ajax_page_handler();
    page_load($(window.location).attr("hash")); // goto first page if #! is available
}

function page_load($href) {
    if($href != undefined && $href.substring(0, 2) == '#/') {
        // replace body the #content with loaded html
        $('#content').load($href.substring(2), function () {
            $('#content').hide().fadeIn('slow');
        });
    }
}

function ajax_page_handler() {
    $(window).bind('hashchange', function () {
        $href = $(window.location).attr("hash");
        page_load($href);
    });

    // this allow you to reload by clicking the same link
    $('a[href^="#/"]').live('click', function() {
        $curhref = $(window.location).attr("hash");
        $href = $(this).attr('href');
        if($curhref == $href) {
            page_load($href);
        }
    });
}

www.krissales.com でのライブ ビューイングは終了しました。フォームはこちら: http://www.krissales.com/#/media/5.Testing-1

リンク「コメントを投稿」をクリックしてから、情報を入力してからコメントを押しますが、更新されるだけで送信されません。

それを解決するために私が取った手順は、コメントファイルのフォームアクションフィールドにあり、name="#content"送信先のdivの名前であるため、タグを挿入しました。

元のものはhttp://blog.krissales.com/article/7.Testing-3-manにあります (実際にコメントを投稿すると機能します)

しかし、どうやらそれは機能していません。私が間違っているのは何かについての手がかりがありますか?事前に助けてくれてありがとう!

<script type="text/javascript">
    tinyMCE.init({
        mode : "textareas",
        theme : "simple"
    });
</script>
<form action="#/media/article.php" name="#content" method="POST">

    Name:
    <br />
    <input type="text" name="name" class="userpass"/>
    <br /><br />
    Comment:
    <br />
    <textarea id="elm1" name="comment" rows="7" cols="30" style="width: 500px;"> 
    </textarea>
    <br />
    <input type="submit" name="submit" value="Comment" class="button" />
    <input type="reset" name="submit" value="Reset" class="button" />

</form> 
4

4 に答える 4

0

現在のcore.jsはURLハッシュの変更を処理し、ハッシュを使用してリンクを再ルーティングして、その相対パスをにロードします#content。不足しているのは、同じことを行うためにフォーム送信をリダイレクトするコードです(これをに追加してくださいajax_page_handler):

 $('form').live('submit', function(e) {
    var $action = $(this).attr('action');

    if($action.substring(0, 2) == '#/') {
        // replace the #content with result of the form post
        $.ajax({
            url: $action.substring(2),
            type: $(this).attr('method'),
            data: $(this).serialize(),
            success: function(data) {
                $('#content').html(data);
                $('#content').hide().fadeIn('slow');
            }
        });
        // stop the real form submit from happening
        e.preventDefault();
    }
});
于 2012-11-23T20:03:59.010 に答える
0

リンクを適切に処理しているようですが、フォームの送信はリンクではありません。おそらく、次を使用して送信を処理する必要があります。$(form).submit(function(){ ... })

あなたの場合、あなたがあなたのフォームにIDを与えたならform1

$('#form1').submit(function(){
  var keyValues = $(this).serializeArray();
  var map = {};
  for(i in keyValues)
  {
    var value = keyValues.value;
    var name = keyValues.name;
    map[name] = value;
  }
  $.post($(this).attr('action'),map,function(){
    alert("Submitted values: " + $(this).serialize());
  });
  return false;
})

詳細についてserializeArrayは、、$.postおよび.submitを参照してください。

于 2012-11-22T12:08:01.630 に答える
0

フォームのアクション属性を次のように変更する必要があります。

<form action="script-handling-comment-data.php#/media/article.php" name="#content" method="POST">

今のところ、コメントデータをhttp://www.krissales.com/に送信していますが、メインページではコメントの投稿を処理していないと思います。

于 2012-11-17T12:09:04.540 に答える