Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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发送两次,event.preventDefault不可用?_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript $.ajax发送两次,event.preventDefault不可用?

Javascript $.ajax发送两次,event.preventDefault不可用?,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我刚刚学习了javascript和jquery,现在我在使用jquery数据表时遇到了一个问题 我的数据被两次发布到php。我不知道如何在我的脚本上实现event.preventDefault并返回false不会起作用 olistorderproduktdatatable = $("#listorderprodukttable").dataTable({ "bJQueryUI": true, "bPaginate": false, "bFilter": true, "bInfo": fa

我刚刚学习了javascript和jquery,现在我在使用jquery数据表时遇到了一个问题

我的数据被两次发布到php。我不知道如何在我的脚本上实现event.preventDefault并返回false不会起作用

olistorderproduktdatatable = $("#listorderprodukttable").dataTable({
    "bJQueryUI": true, "bPaginate": false, "bFilter": true, "bInfo": false, "bAutoWidth": true, "sDom": 'Rlfrtip', 
    "bServerSide": true,
    "sSearch" :"Filter",
    "bDestroy": true,
    "sAjaxSource": "share/content/helper/datatablelistorderprodukt.php" 
});

$('#listorderprodukttable tbody').delegate("tr", "click", rowClickAddPosition);

function rowClickAddPosition(){
    //Welche Zeile wurde selektiert und ID herausfiltern 
   if (hlr)
      $("td:first", hlr).parent().children().each(function(){$(this).removeClass('markrow');});
   hlr = this;
   $("td:first", this).parent().children().each(function(){$(this).addClass('markrow');});

   // You can pull the values out of the row here if required
   var a = $("td:first", this).text();
   var b = $("td:eq(1)", this).text();

   selectedRow      = a;  //ID der Zeile WICHTIGE VARIABLE!!!

    //Abfrage ob ID leer ist, also ob es überhaupt Einträge gibt.
   if(selectedRow != "No matching records found"){
        $.ajax({
            type : 'POST',
            url : 'share/content/helper/orderaddposition.php',
            cache: false,
            data: {
                SelectedProdukt : selectedRow,
                BestellID       : BestellID
            },
            success: function(data) {
                callbackaddposition();
            }
        });
    }
}
我不知道怎么去看比赛?

你有没有试过:

function rowClickAddPosition(e) {
   e.preventDefault();
   // ...
}
在函数中使用并使用
返回false
,如

$('#listorderprodukttable tbody').delegate("tr", "click", function(e){
    rowClickAddPosition(e);
    return false;// to stop bubbling up
});

function rowClickAddPosition(e){
   e.stopPropagation();
   // remaining code

当我实现这一点时,我分析单击行的逻辑将不起作用。selectedRow为空。我现在实现它如下:if(!ajaxLoading){ajaxLoading=true;$.ajax({type:'POST',url:'share/content/helper/orderaddposition.php',cache:false,数据:{SelectedProdukt:selectedRow,BestellID:BestellID},success:function(data){ajaxLoading=false;callbackaddposition();}}}