我怎样才能在AJAX中使用这种var?

时间:2017-02-13 00:34:32

标签: javascript php jquery ajax

问题出在我创建的var中

<script>
$( "#EDITsave" ).click(function() {
  var a = parseInt(window.id.charAt(window.id.length-1)) //a gets parsed correctly but nothing happens in ajax until i set a number myself
  console.log(a) 
  $.ajax({
    type: "POST",
    datatype: "text",
    url: "edit.php",
    data: {
      inputID: a, 
      inputtxt:   //issue is in 'a' here! 
        document.getElementById("editinputtext").value
      },
    });
});
</script>

PHP://用于AJAX的PHP代码

$inputID = $_POST['inputID'];

$inputtxt = $_POST['inputtxt'];


$sql = "UPDATE Contributions SET inputtxt = '$inputtxt'  WHERE inputID   = $inputID";

if ($connection->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $connection->error;
 }

$connection->close();

?>

0 个答案:

没有答案