我在这里尝试 infotuts 的教程: http://www.infotuts.com/ajax-table-add-edit-delete-rows-dynamically-jquery-php/
还有一个像这样的 javascript:
$(function(){
$.ajax({
url:"DbManipulate.php",
type:"POST",
data:"actionfunction=showData",
cache: false,
success: function(response){
$('#demoajax').html(response);
createInput();
}
});
现在我想添加一个参数,以便该行: url:"DbManipulate.php"变成 url:"DbManipulate.php?q=[some value]
我试着像这样修改脚本:
var cat=2;
$(function(){
$.ajax({
url:"DbManipulate.php?q="+cat.val(),
type:"POST",
data:"actionfunction=showData",
cache: false,
success: function(response){
$('#demoajax').html(response);
createInput();
}
});
但它不起作用。变量 cat 永远不会进入函数。如何传递变量“cat”以便 DbManipulate.php 文件接收 $q 变量并且我可以使用 $_GET 来使用它?
谢谢
最佳答案
尝试使用 GET
方法简单地以这种方式发送您的数据变量 (cat)
var cat=2;
$(function(){
$.ajax({
url:"DbManipulate.php",
type:"GET",
data:{actionfunction:showData,cat:cat},
cache: false,
success: function(response){
console.log(response);
$('#demoajax').html(response);
createInput();
}
});
// in DbManipulate.php, try to catch cat using $_GET like this
$cat=$_GET['cat'];
//do further processing
编辑
cat=2;
url="DbManipulate.php";
function yourFunc(cat,url){
$.ajax({
type: "GET",
url: url+'?q='+cat,
dataType: "json",
cache: false,
success: function (response) {
$('#demoajax').html(response);
createInput();
}
});
}
//in DbManipulate.php
$cat=$_GET['q'];
关于javascript - 在javascript中传递一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28259422/