$_GET 在 jQuery select2 中不工作
$_GET not working in jQuery select2
我遇到了一个奇怪的情况。下面是 select2 代码。
$("#tags").select2({
multiple: true,
placeholder: "Please enter tags",
tokenSeparators: [',', ' '],
initSelection : function (element, callback) {
var data = [];
$(element.val().split(",")).each(function () {
data.push({id: this, text: this});
});
callback(data);
},
ajax: {
multiple: true,
url: "fetch.php",
dataType: 'json',
type: "POST",
data: function(term, page) {
return {
term: term
};
},
results: function(data, page) {
return {results: data};
},
},
这是 php 文件 fetch.php
$search = strip_tags(trim($_GET['term']));
问题是 $search 没有任何价值。我检查了 var_dump($_GET) 但没有值。它显示为空。
我检查了 Firebug,发现 post 工作正常,但由于某些原因它没有显示在 $_GET 中。
下面附上屏幕截图。
您正在发布变量,而不是将它们作为查询字符串发送。
Var_dump $_POST 你会找到它们的。
我遇到了一个奇怪的情况。下面是 select2 代码。
$("#tags").select2({
multiple: true,
placeholder: "Please enter tags",
tokenSeparators: [',', ' '],
initSelection : function (element, callback) {
var data = [];
$(element.val().split(",")).each(function () {
data.push({id: this, text: this});
});
callback(data);
},
ajax: {
multiple: true,
url: "fetch.php",
dataType: 'json',
type: "POST",
data: function(term, page) {
return {
term: term
};
},
results: function(data, page) {
return {results: data};
},
},
这是 php 文件 fetch.php
$search = strip_tags(trim($_GET['term']));
问题是 $search 没有任何价值。我检查了 var_dump($_GET) 但没有值。它显示为空。
我检查了 Firebug,发现 post 工作正常,但由于某些原因它没有显示在 $_GET 中。
下面附上屏幕截图。
您正在发布变量,而不是将它们作为查询字符串发送。
Var_dump $_POST 你会找到它们的。