Having trouble passing one parameter through jQuery.ajax()

Discussion in 'jQuery' started by thadrock, Aug 16, 2012.

  1. #1
    Hey All,

    I am currently running a working script with php and jQuery, there is only one issue. When I try to pass the parameter "query" through it is not being captured.

    Here is my jQuery:
    jQuery.ajax({     type: "GET",
         url: '/zipcodesearch',
         data: "query = '07030'",
         async: false,
         beforeSend: function(x) {
          if(x && x.overrideMimeType) {
           x.overrideMimeType("application/j-son;charset=UTF-8");
          }
     },
     dataType: "json",
     success: function(data){
    Code (markup):
    The function is calling success, just not passing this variable through. I have also tried sending it in JSON format as well, no luck

    The PHP is very simple, just a db collection...

    $data = $_GET['data'];
    
            $sql = "SELECT id, zip, city, state
                FROM postal_codes 
                WHERE 
                    zip = '".$data."'";
    Code (markup):
    I know it has to be simple, if someone could please look thanks!
     
    thadrock, Aug 16, 2012 IP
  2. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    Can you try this
    data: {query : '07030' },
    Code (markup):
     
    artus.systems, Aug 17, 2012 IP
  3. thadrock

    thadrock Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No luck... I'm seeing query=07030 on the url when it is being called, but for the life of me... I can't understand why it is not being set!
     
    thadrock, Aug 17, 2012 IP
  4. thadrock

    thadrock Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    My apologies... This was working prior... I was needing to use a POST variable.. THANKS!
     
    thadrock, Aug 17, 2012 IP