我正在尝试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”成为网址:“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来使用它?
谢谢
答案 0 :(得分:0)
尝试使用GET
方法
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'];