Solved

jQuery and SQL to pull and place random text from database

Posted on 2010-09-02
5
317 Views
Last Modified: 2012-05-10
How would one use jQuery to randomly select a column from a table in an SQL database that would then be shown to the user on a page?
0
Comment
Question by:mikesExpertExchange
  • 2
  • 2
5 Comments
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 33591420
this needs to occur when the page loads. and only needs to do the random select once, not on a timer...
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 33592124
if you do it only one time, at page load you should be able to do that on the server side directly.

else of course your answer is ajax : http://api.jquery.com/jQuery.get/

you need to create an .net page returning the random column
<script>
$(document).ready(function() {
    $.get( "page.aspx/randomColum", null, function(data) { $("#here").html(data); } );
});
</script>
<body>
<div id="here"></div>

Open in new window

0
 
LVL 6

Assisted Solution

by:Mike D
Mike D earned 250 total points
ID: 33676516
...and with serverside he means something like

<?

echo "<script>";
echo "var =" . $my_rand_nr;
echo "</script>";

?>

Greets
JD
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
ID: 33801366
thank you.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33801392
You're welcome! Thanks for the points!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now