多值发送 search.php 发送两个值search_word和search_word1。但这两个值都不显示
var search_word = $("#search_box").val();
var search_word1 = $("#check_id").val();
var dataString = 'search_word='+ search_word;
if(search_word=='')
{
}
else
{
$.ajax({
type: "GET",
url: "include/search.php",
data: dataString,
search.php
if(isset($_POST['search_word'])){
$serach_word = $_POST['search_word'];
$serach_word1 = $_POST['search_word1'];
echo "$serach_word<br/>$serach_word1";
}
所以请帮忙。
答案 0 :(得分:3)
答案 1 :(得分:1)
除了David Fregoli之外,您还可以回答,以查询字符串形式发送数据,因为您正在使用GET方法
url: "include/search.php?search_word="+search_word+"&search_word1="+search_word1,
答案 2 :(得分:0)
使用Ajax POST方法:
$.ajax({
type: "POST",
url: "some.php",
data: {name: "John", location: "Boston"}
}).done(
function(msg) {
alert("Data Saved: " + msg);
}
);
答案 3 :(得分:0)
if(search_word=='')
{
}
else
{
$.ajax({
type: "GET",
url: "include/search.php",
data: {
search_word: $("#search_box").val(),
search_word1 :$("#check_id").val()
}
答案 4 :(得分:0)
jQuery简化了任务。语法是
$.get("include/search.php",{search_word:search_word,search_word1:search_word},function(response)
{
alert(response);
});
有关详细信息,请访问https://api.jquery.com/jQuery.get/
答案 5 :(得分:0)
您可以发送选定的数据:
var test = 'yes, this is test string';
...
data: {
testValue: test,
filter: $('#form').find('#name_filter').val()
}
您甚至可以在javascript中序列化整个表单
data: {
filter: $('#form').serialize();
}
并使用简单代码
在PHP中反序列化它$values = array();
parse_str($_POST['filter'], $values);
并且$ values将充满输入/选择/复选框值:)
答案 6 :(得分:0)
您可以尝试使用 $ .param(dataString)
var dataString: {
search_word: $("#search_box").val(),
search_word1: $("#check_id").val()
}
if(dataString)
{
$.ajax({
type: "GET",
url: "include/search.php",
data: $.param(dataString)
});
}
在服务器中:
if(isset($_POST['dataString'])){
$serach_word = $dataString['search_word'];
$serach_word1 = $dataString['search_word1'];
echo "$serach_word<br/>$serach_word1";
}