3

我有输入标签(文本框)和 dxDatagrid。我能够将所有选定的值从 dxDatagrid 传递到数据库,但我也想通过一键单击传递文本框(在网格之外)值。

$("#myButton").dxButton({
    text: "Test",
    onClick: function () {
        var stones = (JSON.stringify(dataGrid.getSelectedRowsData()));
        console.log(stones);
        updatedetgridReturnShip(stones);
    }
});



function updatedetgridReturnShip(stonedetailsarr){
    $('#sloader').show();
    $.ajax({
        url: 'php/insertGridReturnShipment.php',
        dataType: 'json',
        type: "POST",
        data: {
            returnstonedetails: stonedetailsarr,
            txtRefnoval : txtRefnoval
        },
        success: function (result) {
            alert(result);
            $('#sloader').hide();
            $("#myImportModal").modal("hide");
        }
    });
}

PHP服务器端代码:

$StoneArr = json_decode($returnstonedetails, true);

$updstmt = '';

foreach ($StoneArr as $Stone){
  $textboxval = $_POST['textboxval'];

  $refVal = json_decode($textboxval, true);

  $updstmt .= 'CALL return_ship_stones('.'"'.$Stone["carat"].'"'.',
  '.'"'.$Stone["clarity"].'"'.','.'"'.$Stone["color"].'"'.','.'"'.$Stone["invcno"].'"'.','.'"'.$Stone["invoicedate"].'"'.', '.'"'.$Stone["lab"].'"'.', 
  '.'"'.$Stone["measurement"].'"'.' , '.'"'.$Stone["ppt"].'"'.' , '.'"'.$Stone["qstonesid"].'"'.' , '.'"'.$Stone["qty"].'"'.' ,
  '.'"'.$Stone["reportno"].'"'.' , '.'"'.$Stone["shape"].'"'.' , '.'"'.$Stone["totalvalue"].'"'.', '.'"'.$refVal["referenceid"].'"'.');';
}

单击一次如何在数据库中同时传递文本框和 dxDatagrid 值

4

1 回答 1

0

您可以使用jquery方法从 id 输入的文本中获取值并将其传递给ajax数据参数:

$('#refno').val().trim()

下面的代码:

function updatedetgridReturnShip(stonedetailsarr){
    $('#sloader').show();

      $.ajax({
          url: 'php/insertGridReturnShipment.php',
          dataType: 'json',
          type: "POST",
          data: {
              returnstonedetails: stonedetailsarr,
              txtRefnoval : txtRefnoval,
              textboxval: $('#refno').val().trim()
          },
          success: function (result) {
              alert(result);
              $('#sloader').hide();
              $("#myImportModal").modal("hide");
          }
      });
  }

PHP代码:

<?
$returnstonedetails = $_REQUEST['returnstonedetails'];

$StoneArr = json_decode($returnstonedetails, true);

$updstmt = '';

foreach ($StoneArr as $Stone){
  $textboxval = $_REQUEST['textboxval'];
  $refVal = $textboxval;

  $updstmt .= 'CALL return_ship_stones('.'"'.$Stone["carat"].'"'.',
  '.'"'.$Stone["clarity"].'"'.','.'"'.$Stone["color"].'"'.','.'"'.$Stone["invcno"].'"'.','.'"'.$Stone["invoicedate"].'"'.', '.'"'.$Stone["lab"].'"'.', 
  '.'"'.$Stone["measurement"].'"'.' , '.'"'.$Stone["ppt"].'"'.' , '.'"'.$Stone["qstonesid"].'"'.' , '.'"'.$Stone["qty"].'"'.' ,
  '.'"'.$Stone["reportno"].'"'.' , '.'"'.$Stone["shape"].'"'.' , '.'"'.$Stone["totalvalue"].'"'.', '.'"'.$refVal.'"'.');';
}
于 2019-10-22T07:38:50.750 回答