Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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
Php 从循环的$.post()中分别返回2个或多个变量_Php_Jquery - Fatal编程技术网

Php 从循环的$.post()中分别返回2个或多个变量

Php 从循环的$.post()中分别返回2个或多个变量,php,jquery,Php,Jquery,我目前正在开发一个textarea,按下按钮后粘贴的任何内容都将添加到数据库中。将数据库功能放在一边。 我想实现的是: 返回已成功过帐的记录数 返回未插入的记录数,说明其已重复 jquery代码 $(function(){ $('#sw').click(function(){ if($("#txta").val().length>0) { var h=confirm("Are you sure?"); if(h==true) { var

我目前正在开发一个
textarea
,按下按钮后粘贴的任何内容都将添加到数据库中。将数据库功能放在一边。 我想实现的是:

  • 返回已成功过帐的记录数
  • 返回未插入的记录数,说明其已重复
jquery代码

$(function(){
$('#sw').click(function(){
  if($("#txta").val().length>0) 
  {
    var h=confirm("Are you sure?");
    if(h==true)
    {
        var fld=$("#txta").val().split('\n');
        $.each(fld, function(){
          $.post('up.php',
          { 'ldta': this.split('\t') },
          function(data) {
            $('#out').append(data);
          }
          );
        });
        alert('Upload completed');
    }
    else
      alert("Cancelled");
  }
  else
  {
    alert("Textarea is empty.");
    $('#out').html('');
  }
});
});
php


欢迎使用变通方法或想法。

在php代码中使用数组。并使用返回json

$data['first'] = "firstdata";
$data['second'] = array(0=>"iam",1=>"cool");

echo json_encode($data);

谢谢你抽出时间回答。jquery在部分$.post('up.php',{'ldta':this.split('\t')})上传递的数据已经是一个数组。我可以使用诸如$ldta[0]、$ldta[1]等,但我也希望使用变量$dtHK和$line。由于$ldta的值在循环中,因此页面上显示的输出将重复,比如说dtHK是10(表示成功插入了10条记录)'10'将与已创建的一起显示10次。如何获得$dtHK和$line在$each循环之外的值?
function(data) {
    $('#out').append(data);
}
$data['first'] = "firstdata";
$data['second'] = array(0=>"iam",1=>"cool");

echo json_encode($data);