0

我有以下函数调用,我试图将变量 data 的值拉入 data: 函数的部分。我已经做到了这一点,但没有这样的运气让它发挥作用。在 php 中,我使用 $_POST['test'] 来尝试拉取值。

谢谢

function fnc()
 {
   var oButton = document.getElementById("addData");
   var data = document.getElementById("dataInput");
   var display = document.getElementById("display");


     display.innerHTML += "<a id='dispchk'>"+ data.value +"</a>" +"<br />" ;
}
$.ajax({
    type: "POST",
    url: "chkinpost.php?eventid=<?php echo $_GET['eventid']; ?>&eventname=<?php echo $_GET['eventname']; ?>",
    data: "test="+ data.value
});
4

2 回答 2

2

要么不使用function fnc()

var oButton = document.getElementById("addData");
var data = document.getElementById("dataInput");
var display = document.getElementById("display");
display.innerHTML += "<a id='dispchk'>"+ data.value +"</a>" +"<br />" ;
$.ajax({
    type: "POST",
    url: "chkinpost.php?eventid=<?php echo $_GET['eventid']; ?>&eventname=<?php echo $_GET['eventname']; ?>",
    data: "test="+ data.value
});

将您的 AJAX 请求移至function fnc()

function fnc()
{
  var oButton = document.getElementById("addData");
  var data = document.getElementById("dataInput");
  var display = document.getElementById("display");
  display.innerHTML += "<a id='dispchk'>"+ data.value +"</a>" +"<br />" ;
  $.ajax({
    type: "POST",
    url: "chkinpost.php?eventid=<?php echo $_GET['eventid']; ?>&eventname=<?php echo $_GET['eventname']; ?>",
    data: "test="+ data.value
  });
}
于 2013-02-07T20:15:25.103 回答
0

将字符串普通对象作为数据参数传递

var url = "chkinpost.php?eventid=<?php echo $_GET['eventid']; ?>&eventname=<?php echo $_GET['eventname']; ?>"

//var data = { value: "some value"}
//or
var data = 'this is a chicken';

$.ajax({
  type: "POST",
  url: url,
  data: data,
});
于 2013-02-07T20:16:33.307 回答