0

我正在尝试将变量从模态表单传递到另一个页面。我在每个选择中使用 id 标签声明表单中的变量。

页面重新加载到 test.php,但是不能回显任何变量。

javascript

var id = $( "#id" ),
name = $( "#name" )

$.post("jqtest/test.php", { device_id: "id", device_name: "name" });
load('jqtest/test.php');

测试.php

echo $_POST['device_name'];
echo $_POST['device_id'];
4

2 回答 2

0
var id = $( "#id" ), name = $( "#name" )
/*
if have tag like <input id='id' value='ABC'> and want to get ABC , $( "#id" ).val();

if have tag like <div id='id' >ABC</div> and want to get ABC,$( "#id" ).html();
*/
$.post("jqtest/test.php", { device_id: "id", device_name: "name" });
/*
after get id and name , need
$.post("jqtest/test.php", { device_id: id, device_name: name });
*/

load('jqtest/test.php');
/*
  useless delete this line
  if need callback, ref:
  $.post("test.php", { name: "John", time: "2pm" })
    .done(function(data) {
    alert("Data Loaded: " + data);
    });
*/
于 2013-05-03T02:26:36.597 回答
-1

You do not call load to get the contents of the post!

$.post("jqtest/test.php", { device_id: "id", device_name: "name" }, function (data) {
    //handle the response here
    console.log(data);
});

Also the use of load like that is wrong, unless you are calling some sort of function.


Edit,

Based on your comments, the echo does not work since you are loading a NEW page, you are not dealing with the post code in the Ajax request. If you want to navigate to the page the form submits to, than submit an actual form! You are using Ajax wrong.

于 2013-05-03T01:15:18.340 回答