0

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.

2
  • where do put the search words to dataString? Commented Feb 28, 2014 at 10:05
  • i have add. so please what code is write in search.php page Commented Feb 28, 2014 at 10:44

7 Answers 7

3

data has to be a javascrpt object:

data: {
   search_word: search_word,
   search_word1: search_word1
}
Sign up to request clarification or add additional context in comments.

Comments

1

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,

1 Comment

1) Shouldn't there be an '&' character dividing the query strings? 2) What if the value of search_word is 'a&search_word1=b' ?
0
if(search_word=='')
{
}
else
{
$.ajax({
type: "GET",
url: "include/search.php",
data: { 
         search_word: $("#search_box").val(),
         search_word1 :$("#check_id").val()
      }

Comments

0

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/

Comments

0

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 :)

Comments

0

Use Ajax POST method:

$.ajax({
    type: "POST", 
    url: "some.php", 
    data: {name: "John", location: "Boston"} 
}).done(
    function(msg) {
        alert("Data Saved: " + msg);
    }
);

2 Comments

i have used this script for single value send.. so i have multiple value send... please help $(".search_button").click(function() { var search_word = $("#search_box").val(); var dataString = 'search_word='+ search_word; if(search_word=='') { } else { $.ajax({ type: "GET", url: "include/search.php", data: dataString, cache: false,
Please try below code & check jquery version $(".search_button").click(function() { var search_word = $("#search_box").val(); var dataString = {search_word: "search_word", search_word2: "search_word2"}; if (search_word == ''){ }else { $.ajax({ type: "POST", url: "include/search.php", data: dataString, cache: false }).done(function(msg) { console.log(msg) }); } });
0

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";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.