BullGuard Antivirus Sale - 60% Off with openElement !
Forum Home Forum Home >

openElement

> Dynamic OE - Databases, etc
  New Posts New Posts RSS Feed - Put DB data into Visual Code block with AJAX
  FAQ FAQ  Forum Search   Register Register  Login Login

Put DB data into Visual Code block with AJAX

 Post Reply Post Reply
Author
Message
snoopy View Drop Down
Newbie
Newbie


Joined: Jan 06 2017
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote snoopy Quote  Post ReplyReply Direct Link To This Post Topic: Put DB data into Visual Code block with AJAX
    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




Edited by snoopy - Jan 13 2017 at 7:43pm
I am running:
OE 1.56 R4
Windows 10 (64bit) v1607
UniServer Zero XIII 13.3.0
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group


Joined: May 31 2012
Status: Offline
Points: 5283
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: Jan 14 2017 at 9:46am
Hi,

Instead of text() you should use html(), that's all
Back to Top
snoopy View Drop Down
Newbie
Newbie


Joined: Jan 06 2017
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote snoopy Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group


Joined: May 31 2012
Status: Offline
Points: 5283
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Dmit OE View Drop Down
Admin Group
Admin Group


Joined: May 31 2012
Status: Offline
Points: 5283
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.078 seconds.