Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2007
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts

    jquery .ajax help

    I'm having a problem using the jquery ajax() feature. Below is my form code. The ajax call is as simple as you can get. The problem is that nothing is being returned to 'data'.

    I've run the get_last_category_record_id.php script in a browser using http with the one argument company_index=78 and the script returns the test string which is the same data being sent back ('78').

    I'm using Firefox's built-in Debugger and when I step thru the ajax code, 'data' shows a 'ReferenceError: data is not defined'.

    Thanks for any help.

    PHP Code:
      $.ajax({
         
    type"POST",
         
    url"get_last_category_record_id.php",
         
    data: {company_indexcompany_index},
         
    cachefalse,
         
    success: function(data){
         
    alert(data);
         }
       }); 

  • #2
    New Coder
    Join Date
    Sep 2007
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I found this and this code works so I am using it:

    PHP Code:
      $("#ajax_info").load("get_last_category_record_id.php?","company_index="+company_index, function(responeTxt) {
        
    document.getElementById("ajax_info").innerHTML "responeTxt:"+responeTxt;
      }); 

  • #3
    New Coder
    Join Date
    Sep 2007
    Posts
    50
    Thanks
    16
    Thanked 0 Times in 0 Posts
    I do have a question about how to structure the syntax in the called ajax file if I want to return HTML data that will go into a div and also return a responseTxt with some different data?

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The server should return a JSON object. For example:
    Code:
    {"html": "<div>Hello</div>", "somethingelse": "Hi"}
    Then in the js:
    Code:
    $.ajax({ 
         type: "POST", 
         url: "get_last_category_record_id.php", 
         data: {company_index: company_index}, 
         dataType: 'json',
         cache: false, 
         success: function(data){ 
            console.log(data.html); 
            console.log(data.somethingelse); 
         } 
    });
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • Users who have thanked glenngv for this post:

    frank727 (07-22-2013)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •