/    Sign up×
Community /Pin to ProfileBookmark

Is there a limit on jQuery return values?

I have a function which calls ajax to retrieve information from the database, then creates a table to display but it is not working as expected.

“`
var tr = $(this).closest(‘tr’);
var row = table.row( tr );
row.child( getData( row.data()) ).show();`
“`

“`
function getData ( d ) {

var booking;

$.ajax({
async: false,
type: “POST”,
url: “api/bookings.manage.php?h=”+hash,
data: {action: ‘select_row’, booking_id:d[0]},
success: formatTable
});

}
“`

“`
function formatTable ( response ) {

booking = JSON.parse(response);

return ‘<table class=”table”>’+
‘ <thead>’+
‘ <tr>’+
‘ <th scope=”col” colspan=”2″>Booking Details</th>’+
‘ </tr>’+
‘ </thead>’+
‘ <tbody>’+
‘ <tr>’+
‘ <th scope=”row”>Suburb</th>’+
‘ <td>’+booking[0].suburb+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Waste Type</th>’+
‘ <td>’+booking[0].waste_type+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Bin Size</th>’+
‘ <td>’+booking[0].bin_description+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Delivery Date</th>’+
‘ <td>’+booking[0].delivery_date+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Pickup Date</th>’+
‘ <td>’+booking[0].pickup_date+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row” colspan=”2″>Customer Details</th>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Name</th>’+
‘ <td>’+booking[0].firstName+’ ‘+booking[0].lastName+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Email</th>’+
‘ <td>’+booking[0].email+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Company/Business Name</th>’+
‘ <td>’+booking[0].companyName+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Address</th>’+
‘ <td>’+booking[0].address+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Suburb</th>’+
‘ <td>’+booking[0].suburb+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Postcode</th>’+
‘ <td>’+booking[0].postcode+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Daytime Phone</th>’+
‘ <td>’+booking[0].phoneDay+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Mobile Phone</th>’+
‘ <td>’+booking[0].phoneMob+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Billing Address</th>’+
‘ <td>’+booking[0].billToAddress+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row” colspan=”2″>Payment Details</th>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Payment Method</th>’+
‘ <td>’+booking[0].payment_method+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row” colspan=”2″>Other Details</th>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>Additional Information/Delivery Instructions</th>’+
‘ <td>’+booking[0].addit_info+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row”>How did you find us</th>’+
‘ <td>’+booking[0].heard_about_us+’ – ‘+booking[0].heard_other+'</td>’+
‘ </tr>’+
‘ <tr>’+
‘ <th scope=”row” colspan=”2″>Total: $’+booking[0].total_price+’ Inc of GST</th>’+
‘ </tr>’+
‘ </tbody>’+
‘</table>’;
}
“`

When I originally set it up, I simply returned:

`return ‘<h1>TABLE</h1>’;`

This was working fine. Now, when I add the table data, I get:

`Uncaught TypeError: Cannot read property ‘show’ of undefined`

All i can think of is that the return value is too big and it is breaking?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumDec 03.2019 — Your function getData doesn't have a return statement, therefore the console is reporting that it's undefined.

Your function formatTable does have a return statement but this doesn't come into effect.

Try to change your code like this:
var tr = $(this).closest('tr');
var row = table.row( tr );
getData(row);

function getData ( row ) {

<i> </i> var booking;

<i> </i> function formatTable ( response ) {
<i> </i>
<i> </i> booking = JSON.parse(response);
<i> </i>
<i> </i> var thehtml = '&lt;table class="table"&gt;'+
<i> </i> ' &lt;thead&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="col" colspan="2"&gt;Booking Details&lt;/th&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;/thead&gt;'+
<i> </i> ' &lt;tbody&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Suburb&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].suburb+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Waste Type&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].waste_type+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Bin Size&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].bin_description+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Delivery Date&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].delivery_date+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Pickup Date&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].pickup_date+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row" colspan="2"&gt;Customer Details&lt;/th&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Name&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].firstName+' '+booking[0].lastName+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Email&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].email+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Company/Business Name&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].companyName+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Address&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].address+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Suburb&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].suburb+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Postcode&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].postcode+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Daytime Phone&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].phoneDay+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Mobile Phone&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].phoneMob+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Billing Address&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].billToAddress+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row" colspan="2"&gt;Payment Details&lt;/th&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Payment Method&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].payment_method+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row" colspan="2"&gt;Other Details&lt;/th&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;Additional Information/Delivery Instructions&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].addit_info+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row"&gt;How did you find us&lt;/th&gt;'+
<i> </i> ' &lt;td&gt;'+booking[0].heard_about_us+' - '+booking[0].heard_other+'&lt;/td&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;tr&gt;'+
<i> </i> ' &lt;th scope="row" colspan="2"&gt;Total: $'+booking[0].total_price+' Inc of GST&lt;/th&gt;'+
<i> </i> ' &lt;/tr&gt;'+
<i> </i> ' &lt;/tbody&gt;'+
<i> </i> '&lt;/table&gt;';
<i> </i> row.child(thehtml).show();
<i> </i> }
<i> </i>
<i> </i> $.ajax({
<i> </i> async: false,
<i> </i> type: "POST",
<i> </i> url: "api/bookings.manage.php?h="+hash,
<i> </i> data: {action: 'select_row', booking_id:d[0]},
<i> </i> success: formatTable
<i> </i> });

<i> </i>}

Not tested as the JSON and the HTML was not available to me.

BTW: It would be possible to simply the code by using a template string:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
×

Success!

Help @php-bgrader spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...