Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7443833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:23:42+00:00 2026-05-29T11:23:42+00:00

I have been trying to add data from my ajax query that returns json

  • 0

I have been trying to add data from my ajax query that returns json data created in following mode:
$lastedited = $_GET[‘lastload’];

$count = 1;
$JsonArray = Array();


while ($count <= 4) {  // luupataan x määrä ellei vastauksia tule.

$result = mysql_query("SELECT     RFQs.DateAdded as DateAdded,
                              Customers.Name as customer,
                              RFQs.ID as RFQID,
                              Suppliers.Name as supplier,
                              Ships.Name as ship,
                              RFQs.CustomerRef as CustomerRef,
                              Contacts.FirstName as contactF,
                              Contacts.LastName as contactL,
                              Contacts.Email as contactE,
                              Users.tunnus as handler,
                              RFQStatus.Name as status,
                              RFQs.Description
                   FROM       RFQs
                   LEFT JOIN  Ships ON RFQs.ShipID=Ships.ID
                   LEFT JOIN  Contacts ON RFQs.ContactID=Contacts.ID
                   LEFT JOIN  Customers ON RFQs.CustomerID=Customers.idCustomers
                   LEFT JOIN  Users ON RFQs.PriJobHandler=Users.id
                   LEFT JOIN  Suppliers ON RFQs.SupplierID=Suppliers.ID
                   LEFT JOIN  RFQStatus ON RFQs.StatusID=RFQStatus.ID
                   WHERE      RFQs.LastEdited > '$lastedited'
                  ") or die(mysql_error());

if (mysql_num_rows($result) == 0) {
  $count++;
  sleep(5);  // ei uusia rivejä, nukutaan 5 sekuntia ja yritetään uudelleen.
}else {
// käy rivit läpi ja pistää arrayyn  
  for ($x = 0, $numrows = mysql_num_rows($result); $x < $numrows; $x++) {  
    $row = mysql_fetch_assoc($result);  

    array_push($JsonArray, array("rivi" => array("ID" => $row["RFQID"],
                                        "DateAdded" => $row["DateAdded"], 
                                        "Supplier" => $row["supplier"], 
                                        "Customer" => $row["customer"], 
                                        "Ship" => $row["ship"],
                                        "CustomerRef" => $row["CustomerRef"],
                                        "Contact" => $row["contactF"]." ".$row["ContactL"],
                                        "Description" => $row["Description"],
                                        "PIC" => $row["handler"],
                                        "Status" => $row["status"])));  
}
$count = 6;
}

}
if ($count == 5) {
  echo "NO RESULTS!!";
}
else if ($count == 6) {
  //echo JSON to page  
  echo json_encode($JsonArray); 
}

My jQuery goes like this:

<script type="text/javascript" charset="utf-8">

function waitForMsg(lastload){
    if (lastload==null){
      lastload = { "lastload": "<?php echo $lastload; ?>" };
    } 
    $.ajax({
        type: "GET",
        url: "GetUpdates.php",
        datatype: "json",
        data: lastload,
        async: true, /* If set to non-async, browser shows page as "Loading.."*/
        cache: false,
        timeout:50000, /* Timeout in ms */

        success: function(data){ /* kun tulokset saadaan niin suoritetaan.. */
            if (data=="NO RESULTS!!") {
            setTimeout(
                'waitForMsg()',
                1000
            );
            } else {
              displayrow(data.rivi);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            addmsg("error", textStatus + " (" + errorThrown + ")");
            setTimeout(
                'waitForMsg()', /* Try again after.. */
                "15000"); /* milliseconds (15seconds) */
        },
    });
};

$(document).ready(function(){
    waitForMsg(); /* Start the inital request */
});

function displayrow(item)
{
  var tblRow =
            '<td id="showbutton-'+item.ID+'"><a href="#" onclick="hideShow(rowID'+item.ID+'">+</a></td>'
   +'<td id="DateAdded-'+item.ID+'">'+item.DateAdded+'</td>'
   +'<td id="Supplier-'+item.ID+'">'+item.Supplier+'</td>'
   +'<td id="Customer-'+item.ID+'">'+item.Customer+'</td>'
   +'<td id="Ship-'+item.ID+'">'+item.Ship+'</td>'
   +'<td id="CustomerRef-'+item.ID+'">'+item.CustomerRef+'</td>'
   +'<td id="Contact-'+item.ID+'">'+item.Contact+'</td>'
   +'<td id="Description-'+item.ID+'">'+item.Description+'</td>'
   +'<td id="PIC-'+item.ID+'">'+item.PIC+'</td>'
   +'<td id="Status-'+item.ID+'">'+item.Status+'</td>'
   +'<td id="Actions-'+item.ID+'">Hit F5 for actions</td>';
   $('#newRFQrowInput').before(tblRow);
}
</script>

Problem is I’m not sure how I should process this data coming back from ajax query.
At the moment all I’m getting is undefined.

Can some one help?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:23:43+00:00Added an answer on May 29, 2026 at 11:23 am

    Make changes in your .php file that send back information

    $JsonArray = array("ID" => $row["RFQID"],
                        "DateAdded" => $row["DateAdded"], 
                        "Supplier" => $row["supplier"], 
                        "Customer" => $row["customer"], 
                        "Ship" => $row["ship"],
                        "CustomerRef" => $row["CustomerRef"],
                        "Contact" => $row["contactF"]." ".$row["ContactL"],
                        "Description" => $row["Description"],
                        "PIC" => $row["handler"],
                        "Status" => $row["status"]
                );
    echo json_encode(array('rivi'=>$JsonArray));
    

    UPDATE:

    make changes in your “For loop”

    $JsonArray = array();
    for ($x = 0, $numrows = mysql_num_rows($result); $x < $numrows; $x++) {  
        while($row = mysql_fetch_assoc($result)){
            array_push($JsonArray,array("ID" => $row["RFQID"],
                                        "DateAdded" => $row["DateAdded"], 
                                        "Supplier" => $row["supplier"], 
                                        "Customer" => $row["customer"], 
                                        "Ship" => $row["ship"],
                                        "CustomerRef" => $row["CustomerRef"],
                                        "Contact" => $row["contactF"]." ".$row["ContactL"],
                                        "Description" => $row["Description"],
                                        "PIC" => $row["handler"],
                                        "Status" => $row["status"]
                                        )
                    ); 
        }
    
    }
    

    Replace this with yours

    else if ($count == 6) {
      //echo JSON to page  
      echo json_encode(array("rivi" =>$JsonArray)); 
    }
    

    and in ajax success function also.

    success:function(data){
        if(data.rivi.length){
            //alert(data.rivi.length);
            displayrow(data.rivi);
        }               
    }
    

    Then at last in your displayrow function

    function displayrow($item){
        var tblRow = '<table>';
        $.each($item,function(index,value){
            tblRow +='<tr><td id="showbutton-'+value.ID+'"><a href="#" onclick="hideShow(rowID'+value.ID+'">+</a></td>'
                   +'<td id="DateAdded-'+value.ID+'">'+value.DateAdded+'</td>'
                   +'<td id="Supplier-'+value.ID+'">'+value.Supplier+'</td>'
                   +'<td id="Customer-'+value.ID+'">'+value.Customer+'</td>'
                   +'<td id="Ship-'+value.ID+'">'+value.Ship+'</td>'
                   +'<td id="CustomerRef-'+value.ID+'">'+value.CustomerRef+'</td>'
                   +'<td id="Contact-'+value.ID+'">'+value.Contact+'</td>'
                   +'<td id="Description-'+value.ID+'">'+value.Description+'</td>'
                   +'<td id="PIC-'+value.ID+'">'+value.PIC+'</td>'
                   +'<td id="Status-'+value.ID+'">'+value.Status+'</td>'
                   +'<td id="Actions-'+value.ID+'">Hit F5 for actions</td></tr>';
        }   
       tblRow = '</table>';
       $('#newRFQrowInput').before(tblRow);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to add to the Watch window a Java Date object
At www.euroworker.no/order I have been trying to add a tooltip function but it seems
I have been trying to learn how to add testing to existing code --
I want to add a thumbnail picture viewer to my application.I have been trying
I have been trying to add an object as an NSMutableDictionary to my array,
I currently have a DetailsView in ASP.NET that gets data from the database based
I have an small ASP.NET application that reads data from a table and sends
Assuming that the data has been retrieved from the Db and put into an
First off I'm new to Android and Java.. I have been trying to add
I've been trying to figure out a way of presenting data dynamically but have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.