#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7

    Response from AJAX call not printing to page


    Ok. I rarely use javascript, let along js/ajax in this manner. The link directs you to the script that is to run and return what is to be printed to the page.

    When the page is accessed directly, with a manual id tossed in the address, the desired result is printed to the screen. When called upon by the full code, it seems nothing happens. Am I perhaps referencing something wrong?

    Direct link: http://kdna.jtgcomputers.com/modules...ll.php?CID=154
    livecall.php
    PHP Code:
      error_reporting(E_ALL);
      include(
    '../../includes/db.php');
      function 
    buildSerial($selectedID) {
        global 
    $link;
        
    $statement $link->prepare("SELECT `ID`,`Serial Number` FROM `machines` WHERE `CustomerID` = ? ORDER BY `Serial Number`");
        
    $statement->bind_param('i'$selectedID);
        
    $statement->execute();
        
    $statement->bind_result($col1,$col2);
        while (
    $statement->fetch()) {
          
    $selected = ($selectedID == $col1 " selected" "");
          echo 
    '                                <OPTION value="' $col1 '"' $selected '>' $col2 "</OPTION>\n";
        }
        
    $statement->close();
      }

      if(isset(
    $_GET['CID'])){
        
    buildSerial($_GET['CID']);
      } 
    Front-end:
    PHP Code:
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script>
      function getMID(id) {
        $.ajax({
          type: "GET",
          url: "http://kdna.jtgcomputers.com/modules/serv/livecall.php",
          data: "CID =" + id,
          success: function(result){
            $('#MIDS').html(result);
          }
        });
      };
    </script>
    <DIV id="MIDS"></DIV>
    <?php
      
    if($action == "add" || $action == "edit") {
        echo 
    '<SELECT name="CID" id="CID" onchange="getMID(this.value);">\n';
        
    buildCustomer($var['companyID']);
        echo 
    '</SELECT>';
      } else {
        echo 
    $var['Customer Name'];
      }
    ?>
    Last edited by Triple_Nothing; August 13th, 2013 at 04:19 PM.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,165
    Rep Power
    184
    I think your <OPTION> tags are not displaying, because you do not have them wrapped in a <SELECT> tag; try this and see if it works:
    Code:
    // jQuery
    $("#MIDS select").html(result);
    
    <!-- HTML -->
    <DIV id="MIDS">
    <select></select>
    </DIV>
    Oh, and... remove the space here and see if that makes a difference, as well
    Code:
    data: "CID =" + id,
    try this instead:
    Code:
    data: "CID=" + id,
    Last edited by web_loone08; August 13th, 2013 at 04:44 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    677
    Rep Power
    7
    Ah, twas the space. Gotta love how strict some code may be.

IMN logo majestic logo threadwatch logo seochat tools logo