AJAX:传递多个变量 [英] AJAX : passing multiple variables
本文介绍了AJAX:传递多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
传递一个变量有效:
var type = $.cookie('liste-voyage-type');
var code= $.cookie('liste-voyage-code');
$.ajax({
url : '../listing-voyage-produit.php',
type : 'GET' ,
data : 'type=' + type;
});
listing-voyage-produit.php
listing-voyage-produit.php
$type = $_GET['type'];
echo 'type' . $type; // => 2
但是我不能让它使用2个变量:
But I cannot make it working with 2 variables:
$.ajax({
url : '../listing-voyage-produit.php',
type : 'GET' ,
data : 'type=' + type+'&code=' + code;
});
listing-voyage-produit.php
listing-voyage-produit.php
$code = $_GET['code'];
echo 'code' . $code; // => !?
推荐答案
您无需将数据转换为字符串参数. jQuery将为您做到这一点.试试这个
You need not to convert data into string parameters. Jquery will do that for you. Try this
var type = $.cookie('liste-voyage-type');
var code= $.cookie('liste-voyage-code');
var myData = {
type: type,
code: code
};
$.ajax({
url : '../listing-voyage-produit.php',
type : 'GET' ,
data : myData
});
这篇关于AJAX:传递多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文