Author Topic: Passing php variable to a function called in jquery ajax help  (Read 1089 times)

0 Members and 1 Guest are viewing this topic.

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
My code is below. I'm wanting to pass the php variable $db, to the function called.
The line where I'm having issues is
db: <?php echo $db ?>

Code: [Select]
$(document).ready(function() {
    $('#wait_1').hide();
    $('#drop_1').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "drop_1",
        drop_var: $('#drop_1').val()
        db: <?php echo $db ?>
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});

How can it be done? Thanks
« Last Edit: May 15, 2010, 10:46:38 AM by TeddyKiller »
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline CodeMaster

  • Irregular
  • Posts: 39
  • Gender: Male
    • View Profile
Re: Passing php variable to a function called in jquery ajax help
« Reply #1 on: May 15, 2010, 02:59:30 PM »
You need to put quotes around the value and a comma on the line above. Like this:

Code: [Select]
$(document).ready(function() {
    $('#wait_1').hide();
    $('#drop_1').change(function(){
      $('#wait_1').show();
      $('#result_1').hide();
      $.get("func.php", {
        func: "drop_1",
        drop_var: $('#drop_1').val(),
        db: "<?php echo $db ?>"
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
        return false;
    });
});