Using Jquery Ajax to retrieve data from Mysql

0 votes

list.php: A simple ajax code that I want to display only records of the Mysql table:

<html>

<head>
    <script src="jquery-1.9.1.min.js">
    </script>
    <script>
    $(document).ready(function() {
        var response = '';
        $.ajax({
            type: "GET",
            url: "Records.php",
            async: false,
            success: function(text) {
                response = text;
            }
        });

        alert(response);
    });
    </script>
</head>

<body>
    <div id="div1">
        <h2>Let jQuery AJAX Change This Text</h2>
    </div>
    <button>Get Records</button>
</body>

</html>

Records.php is the file to fetch records from Mysql.
In the Database are only two fields: 'Name', 'Address'.

<?php
    //database name = "simple_ajax"
    //table name = "users"
    $con = mysql_connect("localhost","root","");
    $dbs = mysql_select_db("simple_ajax",$con);
    $result= mysql_query("select * from users");
    $array = mysql_fetch_row($result);
?>
<tr>
    <td>Name: </td>
    <td>Address: </td>
</tr>
<?php
    while ($row = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>$row[1]</td>";
        echo "<td>$row[2]</td>";
        echo "</tr>";
    }   
?>

This code is not working.

Jun 23 in Web Development by gaurav
• 18,960 points
1,113 views

1 answer to this question.

0 votes

Perform a AJAX GET request to get data from server

  1. Create a MySQL table and insert data.
  2. Create HTML form and jQuery script to perform AJAX GET Request to PHP MySQL Server.
  3. Write a PHP script to receive request from client and fetch data from MySQL database and send a JSON encoded result to client.
answered Jun 23 by rajatha
• 7,440 points

Related Questions In Web Development

0 votes
0 answers
0 votes
0 answers

jQuery to load random image from array using chickendinner.js returning 'undefined' in Chrome

I have the following jQuery script setup ...READ MORE

Jul 27 in Web Development by gaurav
• 18,960 points
79 views
0 votes
0 answers

How to obtain data from random wikipedia page with jquery

$(".wikiResult h3").load("https://en.wikipedia.org/wiki/Special:Random #firstHeading i"); I would like to ...READ MORE

Aug 11 in Web Development by gaurav
• 18,960 points
45 views
0 votes
0 answers

Using jQuery to countdown from 90 seconds beginning on the click of an element

Hi I was wondering if anyone can ...READ MORE

Aug 22 in Web Development by gaurav
• 18,960 points
23 views
0 votes
0 answers

Edit PHP query code depending on image map clicked area using AJAX

I am working on an image map ...READ MORE

Jun 3 in PHP by Kichu
• 19,040 points
33 views
0 votes
0 answers

Using Jquery Ajax to retrieve data from Mysql

list.php: A simple ajax code that I ...READ MORE

Jun 20 in PHP by Kithuzzz
• 12,240 points
127 views
0 votes
0 answers

How to run a PHP function due to a button click (with button 'data' passed)?

I manage some sortiment items on a ...READ MORE

May 28 in PHP by Kichu
• 19,040 points
1,929 views
0 votes
2 answers

Define a SQL query? What is the difference between SELECT and UPDATE Query? How do you use SQL in SAS?

HI.. SQL is Structured Query Language, which is ...READ MORE

answered Aug 8, 2020 in PHP by anonymous
5,049 views
0 votes
1 answer

How to place images using jQuery masonry plugin to start

You were just missing a css class that adjusts ...READ MORE

answered Jun 22 in Web Development by rajatha
• 7,440 points
32 views
0 votes
1 answer

How to create a simple map using JavaScript/JQuery

var map = new Object(); // or ...READ MORE

answered Jun 27 in Web Development by rajatha
• 7,440 points
51 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP