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
• 13,460 points
9 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
• 4,940 points

Related Questions In Web Development

0 votes
1 answer

How to upload zip from the S3 bucket to lambda function using AWS CLI

Hi@Abhishek, You want to upload your zip file ...READ MORE

answered Apr 10, 2020 in Web Development by MD
• 95,360 points
4,305 views
0 votes
1 answer

How to download a file by jQuery.Ajax?

Hello @kartik, You don't need to do this ...READ MORE

answered Sep 18, 2020 in Web Development by Niroj
• 82,720 points
5,416 views
0 votes
1 answer

How to alert using jQuery

alert($('#test')); // or alert($('#test'). get(0)); // also try alert(document. ...READ MORE

answered 3 days ago in Web Development by rajatha
• 4,940 points
8 views
0 votes
1 answer

How to Fade In/Out multiple texts using CSS/jQuery like on Droplr?

The jQuery fadeIn() method is used to ...READ MORE

answered 1 day ago in Web Development by rajatha
• 4,940 points
4 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
10 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
• 320 points
9 views
0 votes
0 answers
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
4,482 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
• 4,940 points
6 views
0 votes
1 answer

How to create a simple map using JavaScript/JQuery

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

answered 3 days ago in Web Development by rajatha
• 4,940 points
2 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP