Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.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 阻止A HREF重定向但仍在完成操作?_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 阻止A HREF重定向但仍在完成操作?

Javascript 阻止A HREF重定向但仍在完成操作?,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,我有一个使用Jquery移动列表视图的页面。我试图找到一种保持listview外观的方法,但是有一个执行命令的按钮,而不像普通的按钮那样重定向 以下是AHREF的生成方式 if ($result = mysqli_query($link, $query)) { /* fetch associative array */ while ($row = mysqli_fetch_assoc($result)) { if ($row['photoLink'] == NUL

我有一个使用Jquery移动列表视图的页面。我试图找到一种保持listview外观的方法,但是有一个执行命令的按钮,而不像普通的按钮那样重定向

以下是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);
}
if($result=mysqli\u查询($link,$query)){
/*获取关联数组*/
while($row=mysqli\u fetch\u assoc($result)){
if($row['photoLink']==NULL)
{
$row['photoLink']=“endofgroup”;
$row['lastName']=“组结束”;
$ID=“&ID=”.$row['ID'];
}
如果($row[leftGym]=“1”){$flash=“style='color:#B22222;字体大小:140%”;}其他{$flash=”“}
$row['firstName']=strtoupper($row['firstName']);
$row['lastName']=strtoupper($row['lastName']);
回声“
  • ”; } /*自由结果集*/ mysqli_免费_结果($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>
    
    
    $(函数(){
    //附加click事件并执行此功能
    $(“a”)。在('click',函数(e){
    e、 preventDefault();//防止页面导航,这是链接的默认行为
    $.ajax({
    url:this.href,//使用链接执行ajax请求
    /*类型:POST,*/
    beforeSend:function(){
    $(“#状态”).text('工作…)
    }
    }).完成(功能(数据){
    console.log(data);//如果有数据,请对其进行处理
    }).fail(函数(jqXHR、textStatus、errorshown){
    console.log(“ERROR”);//在控制台中报告错误
    控制台信息(jqXHR);
    控制台信息(文本状态);
    控制台信息(错误抛出);
    }).always(函数(){
    $(“#状态”).text('已完成…)
    console.info(“completed”);//无论结果如何,每次都执行此步骤
    });
    })
    })
    
    有人能看出我做错了什么吗?或者我的想法可能吗?有没有更好的办法?我只希望用户能够单击链接,停留在同一页面上,但在引用页面上处理脚本


    提前谢谢

    返回false在单击函数的末尾。如果没有这样做,您的数据库响应正在返回重定向的东西。

    我在中间找到了一个标题:位置PHP。那会导致它吗?那是你的问题,那就解决了,非常感谢。我没有意识到,在使用prevent default时,它仍然会遵守头重定向。但这是有意义的-prevent default只会影响我刚刚意识到的A标记。