multiple value send search.php send two value search_word and search_word1. but both value is not display
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";
}
so Please Help.
data
has to be a javascrpt object:
data: {
search_word: search_word,
search_word1: search_word1
}
Use Ajax POST method:
$.ajax({
type: "POST",
url: "some.php",
data: {name: "John", location: "Boston"}
}).done(
function(msg) {
alert("Data Saved: " + msg);
}
);
if(search_word=='')
{
}
else
{
$.ajax({
type: "GET",
url: "include/search.php",
data: {
search_word: $("#search_box").val(),
search_word1 :$("#check_id").val()
}
Apart form David Fregoli answer you can also,send data in query string form,as you are using GET Method
url: "include/search.php?search_word="+search_word+"&search_word1="+search_word1,
jQuery simplifies the task. The syntax is
$.get("include/search.php",{search_word:search_word,search_word1:search_word},function(response)
{
alert(response);
});
For more details visit https://api.jquery.com/jQuery.get/
You can send selected data:
var test = 'yes, this is test string';
...
data: {
testValue: test,
filter: $('#form').find('#name_filter').val()
}
You can even serialize whole form in javascript
data: {
filter: $('#form').serialize();
}
and deserialize it in PHP with simple code
$values = array();
parse_str($_POST['filter'], $values);
And $values will be full of inputs/select/checkbox values :)
You can try using $.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)
});
}
In Server:
if(isset($_POST['dataString'])){
$serach_word = $dataString['search_word'];
$serach_word1 = $dataString['search_word1'];
echo "$serach_word<br/>$serach_word1";
}