BullGuard Antivirus Sale - 60% Off with openElement !
Forum openElement Homepage
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: 06 Jan 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: 13 Jan 2017 at 19:05
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 - 13 Jan 2017 at 20:43
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
Avatar

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

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


Joined: 06 Jan 2017
Status: Offline
Points: 27
Post Options Post Options   Thanks (0) Thanks(0)   Quote snoopy Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jan 2017 at 11:46
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
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5215
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jan 2017 at 12:45
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
Avatar

Joined: 31 Mai 2012
Status: Offline
Points: 5215
Post Options Post Options   Thanks (1) Thanks(1)   Quote Dmit OE Quote  Post ReplyReply Direct Link To This Post Posted: 14 Jan 2017 at 12:47
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 10.11
Copyright ©2001-2012 Web Wiz Ltd.

This page was generated in 0,031 seconds.