Print Page | Close Window

Put DB data into Visual Code block with AJAX

Printed From: openElement Website
Category:

openElement


Forum Name: Dynamic OE - Databases, etc
Forum Description: openElement's database management system and Element Packs
URL: https://forums.openelement.uk/en/forum_posts.asp?TID=941
Printed Date: Apr 19 2024 at 9:31am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Put DB data into Visual Code block with AJAX
Posted By: snoopy
Subject: Put DB data into Visual Code block with AJAX
Date Posted: Jan 13 2017 at 6:05pm
I have now a working page with a Visual Code block that fills itself with rows from a DB.
The Code Block uses PHP to do this, and it uses the command 'echo' to generate HTML code, to put the DB data into a table (displayed by the Visual Code block).

Now I am struggling to use AJAX to do this instead and it almost works ....
I have put the PHP code from the Visual Code block into a separate PHP file.

The HTML code is received correctly from the PHP file by the 'xmlhttp.onreadystatechange = function()'.
The problem is that I can't get the Visual Code block to output the HTML code as a table.

When I use the code:

var titleRows = this.responseText;
$('.arrListBox').text(titleRows);

the HTML code ('<TABLE .....') is displayed in the '.arrListBox' (the Visual Code block) instead of the DB data (the CD titles).
I have also tested per the example at 'http://www.w3schools.com/php/php_ajax_database.asp' with '$('.arrListBox').innerHTML' and other combinations of params. without success.


How do I get the Visual Code block to display the data resulting from the HTML code instead of the HTML code??


Best regards,
Erland




-------------
I am running:
OE 1.56 R4
Windows 10 (64bit) v1607
UniServer Zero XIII 13.3.0



Replies:
Posted By: Dmit OE
Date Posted: Jan 14 2017 at 9:46am
Hi,

Instead of text() you should use html(), that's all


Posted By: snoopy
Date Posted: Jan 14 2017 at 10:46am
Thank's again Dmit!!

For future reference.... 
How do I find the name of the attribute I should use?
Where to find the available attribute names?

That is should I use:
$('.arrListBox').text($titleRows);  or...
$('.arrListBox').val($titleRows); or...
$('.arrListBox').html($titleRows); or...
$('.arrListBox').attr('someOtherAttr', $titleRows);
or some other name....


Best regards,
Erland


-------------
I am running:
OE 1.56 R4
Windows 10 (64bit) v1607
UniServer Zero XIII 13.3.0


Posted By: Dmit OE
Date Posted: Jan 14 2017 at 11:45am
Google and jQuery API help is your guide. Just type for example "jQuery val" in Google and you will see what it's for and examples of usage. There are many very good answers on StackOverflow as well, with ready-to-use examples


Posted By: Dmit OE
Date Posted: Jan 14 2017 at 11:47am
P.S. An attribute in HTML is what's inside the declaration of a tag, example:

<div class='myclass' style='display:inline-block;" data-value='myvalue'>

This DIV tag has 3 attributes: class, style and data-value



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net