2016-12-22 7 views
2

Jquery Mobileのリストビューを使用するページがあります。私はlistviewの外観を維持する方法を見つけようとしていますが、通常のようにリダイレクトせずにコマンドを実行するボタンを持っています。HREFリダイレクトを防止してもアクションは完了していますか?

Ahrefがどのように生成されるかを示します。

if ($result = mysqli_query($link, $query)) { 
    /* fetch associative array */ 
    while ($row = mysqli_fetch_assoc($result)) { 
     if ($row['photoLink'] == NULL) 
     { 
      $row['photoLink'] = "endofgroup"; 
      $row['lastName'] = "End Of Group " ; 
      $ID = "&ID=".$row['ID']; 
     } 
     if ($row[leftGym] == "1") { $flash = "style='color:#B22222;font-size:140%'";} else {$flash ="";} 
      $row['firstName'] = strtoupper($row['firstName']); 
     $row['lastName'] = strtoupper($row['lastName']); 
      echo "<li><a href='WPSelect.php?sid=${row['sID']}' $flash style='font-size:140%;' width='25px' data-ajax='false'>&nbsp; &nbsp; {$row["lastName"]}, {$row["firstName"]}</a><div class='split-custom-wrapper'> 
      <a href='WDData.php?sID={$row['sID']}&lane=1{$ID}' data-role='button' class='split-custom-button' data-icon='delete' data-rel='dialog' data-theme='c' data-ajax='false' data-iconpos='notext'></a>   
     </div></li>"; 
    } 
    /* free result set */ 
    mysqli_free_result($result); 
} 

と、ここで私は

<script> 
$(function() { 
//Attache the click event and perform this function 
    $("a").on('click', function(e) { 
    e.preventDefault(); //preven the page from navigating, the default behaviour for a link 
    $.ajax({ 
     url: this.href, //perform a ajax request witht the link 
     /* type: POST, */ 
     beforeSend: function() { 
     $("#status").text('Working..') 
     } 
    }).done(function(data) { 
     console.log(data); //do something with the data if any 
    }).fail(function(jqXHR, textStatus, errorThrown) { 
     console.log("ERROR"); //report in console for errors 
     console.info(jqXHR); 
     console.info(textStatus); 
     console.info(errorThrown); 
    }).always(function() { 
     $("#status").text('completed..') 
     console.info("completed"); //do this step everytime irrespective of result 
    }); 
    }) 
}) 
</script> 

誰もが私が間違っていることができるか見ることができますをしようとしたコードがありますか?それとも私の考えは可能ですか?これについてもっと良い方法がありますか?私が望むのは、ユーザーがリンクをクリックしたり、同じページに留まったり、参照されているページでスクリプトを処理できることだけです。

ありがとうございます!

答えて

3

return false;クリックの機能が終了しました。それがしなければ、データベースの応答はリダイレクトするものを返しています。

+0

私はヘッダーを見つけました:真ん中に位置php。それが原因でしょうか? –

+0

それはあなたの問題です – mopsyd

+1

それはそれを固定しました、ありがとうございます。私はそれがまだデフォルトを防ぐのを使用するときそれがヘッダーのリダイレクトに従うであろうことに気づいていませんでした。しかしそれは理にかなっています - 防止デフォルトは私がちょうど実現したタグに影響を与えます。 –

関連する問題