Using Jquery Ajax to retrieve data from Mysql





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







29















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.










share|improve this question




















  • 2





    What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

    – Phil Cross
    May 23 '13 at 7:10






  • 1





    Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

    – V.Vachev
    May 23 '13 at 7:12













  • @PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

    – Ravi
    May 23 '13 at 7:55






  • 1





    What output do you exactly get ?

    – Þaw
    May 23 '13 at 8:20


















29















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.










share|improve this question




















  • 2





    What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

    – Phil Cross
    May 23 '13 at 7:10






  • 1





    Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

    – V.Vachev
    May 23 '13 at 7:12













  • @PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

    – Ravi
    May 23 '13 at 7:55






  • 1





    What output do you exactly get ?

    – Þaw
    May 23 '13 at 8:20














29












29








29


26






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.










share|improve this question
















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.







php mysql ajax jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 19 at 7:07









Tushar Walzade

2,27931935




2,27931935










asked May 23 '13 at 7:06









RaviRavi

4021615




4021615








  • 2





    What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

    – Phil Cross
    May 23 '13 at 7:10






  • 1





    Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

    – V.Vachev
    May 23 '13 at 7:12













  • @PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

    – Ravi
    May 23 '13 at 7:55






  • 1





    What output do you exactly get ?

    – Þaw
    May 23 '13 at 8:20














  • 2





    What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

    – Phil Cross
    May 23 '13 at 7:10






  • 1





    Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

    – V.Vachev
    May 23 '13 at 7:12













  • @PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

    – Ravi
    May 23 '13 at 7:55






  • 1





    What output do you exactly get ?

    – Þaw
    May 23 '13 at 8:20








2




2





What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

– Phil Cross
May 23 '13 at 7:10





What happens when you go to Records.php directly? Are there any error messages? You need to be more precise with whats not working.

– Phil Cross
May 23 '13 at 7:10




1




1





Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

– V.Vachev
May 23 '13 at 7:12







Are 1 and 2 names of columns in the table 'users'? If they are, try with echo "<td>".$row['1']."</td>"; In records.php

– V.Vachev
May 23 '13 at 7:12















@PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

– Ravi
May 23 '13 at 7:55





@PhilCross: There is no any error is given it just put as a result for content on Respons.php , as file i have write as a output.

– Ravi
May 23 '13 at 7:55




1




1





What output do you exactly get ?

– Þaw
May 23 '13 at 8:20





What output do you exactly get ?

– Þaw
May 23 '13 at 8:20












4 Answers
4






active

oldest

votes


















53














For retrieving data using Ajax+jQuery, you must write the following code:



 <html>
<script type="text/javascript" src="jquery-1.3.2.js"> </script>

<script type="text/javascript">

$(document).ready(function() {

$("#display").click(function() {

$.ajax({ //create an ajax request to display.php
type: "GET",
url: "display.php",
dataType: "html", //expect html to be returned
success: function(response){
$("#responsecontainer").html(response);
//alert(response);
}

});
});
});

</script>

<body>
<h3 align="center">Manage Student Details</h3>
<table border="1" align="center">
<tr>
<td> <input type="button" id="display" value="Display All Data" /> </td>
</tr>
</table>
<div id="responsecontainer" align="center">

</div>
</body>
</html>


For mysqli connection, write this:



<?php 
$con=mysqli_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
?>


For displaying the data from database, you must write this :



<?php
include("connection.php");
mysqli_select_db("samples",$con);
$result=mysqli_query("select * from student",$con);

echo "<table border='1' >
<tr>
<td align=center> <b>Roll No</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Address</b></td>
<td align=center><b>Stream</b></td></td>
<td align=center><b>Status</b></td>";

while($data = mysqli_fetch_row($result))
{
echo "<tr>";
echo "<td align=center>$data[0]</td>";
echo "<td align=center>$data[1]</td>";
echo "<td align=center>$data[2]</td>";
echo "<td align=center>$data[3]</td>";
echo "<td align=center>$data[4]</td>";
echo "</tr>";
}
echo "</table>";
?>





share|improve this answer





















  • 7





    Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

    – Amal Murali
    Apr 23 '14 at 21:57











  • Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

    – user3816325
    May 19 '16 at 3:50











  • @user3816325 check your server. I believe your server isnt running.

    – prakashchhetri
    Sep 10 '16 at 13:23



















4
















You can't return ajax return value. You stored global variable store your return values after return.

Or Change ur code like this one.



AjaxGet = function (url) {
var result = $.ajax({
type: "POST",
url: url,
param: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
// nothing needed here
}
}) .responseText ;
return result;
}








share|improve this answer
























  • without Json i have to do.

    – Ravi
    May 23 '13 at 7:59











  • @RaviParmar change datatype "html".This is for example.

    – Mariselvam Panneerselvam
    May 23 '13 at 8:49





















2














Please make sure your $row[1] , $row[2] contains correct value, we do assume here that 1 = Name , and 2 here is your Address field ?



Assuming you have correctly fetched your records from your Records.php, You can do something like this:



$(document).ready(function()
{
$('#getRecords').click(function()
{
var response = '';
$.ajax({ type: 'POST',
url: "Records.php",
async: false,
success : function(text){
$('#table1').html(text);
}
});
});

}


In your HTML



<table id="table1"> 
//Let jQuery AJAX Change This Text
</table>
<button id='getRecords'>Get Records</button>


A little note:



Try learing PDO http://php.net/manual/en/class.pdo.php since mysql_* functions are no longer encouraged..






share|improve this answer

































    1














    $(document).ready(function(){
    var response = '';
    $.ajax({ type: "GET",
    url: "Records.php",
    async: false,
    success : function(text)
    {
    response = text;
    }
    });

    alert(response);
    });


    needs to be:



    $(document).ready(function(){

    $.ajax({ type: "GET",
    url: "Records.php",
    async: false,
    success : function(text)
    {
    alert(text);
    }
    });

    });





    share|improve this answer
























      protected by Community Feb 19 '14 at 5:43



      Thank you for your interest in this question.
      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



      Would you like to answer one of these unanswered questions instead?














      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      53














      For retrieving data using Ajax+jQuery, you must write the following code:



       <html>
      <script type="text/javascript" src="jquery-1.3.2.js"> </script>

      <script type="text/javascript">

      $(document).ready(function() {

      $("#display").click(function() {

      $.ajax({ //create an ajax request to display.php
      type: "GET",
      url: "display.php",
      dataType: "html", //expect html to be returned
      success: function(response){
      $("#responsecontainer").html(response);
      //alert(response);
      }

      });
      });
      });

      </script>

      <body>
      <h3 align="center">Manage Student Details</h3>
      <table border="1" align="center">
      <tr>
      <td> <input type="button" id="display" value="Display All Data" /> </td>
      </tr>
      </table>
      <div id="responsecontainer" align="center">

      </div>
      </body>
      </html>


      For mysqli connection, write this:



      <?php 
      $con=mysqli_connect("localhost","root","");
      if (!$con)
      {
      die('Could not connect: ' . mysqli_error());
      }
      ?>


      For displaying the data from database, you must write this :



      <?php
      include("connection.php");
      mysqli_select_db("samples",$con);
      $result=mysqli_query("select * from student",$con);

      echo "<table border='1' >
      <tr>
      <td align=center> <b>Roll No</b></td>
      <td align=center><b>Name</b></td>
      <td align=center><b>Address</b></td>
      <td align=center><b>Stream</b></td></td>
      <td align=center><b>Status</b></td>";

      while($data = mysqli_fetch_row($result))
      {
      echo "<tr>";
      echo "<td align=center>$data[0]</td>";
      echo "<td align=center>$data[1]</td>";
      echo "<td align=center>$data[2]</td>";
      echo "<td align=center>$data[3]</td>";
      echo "<td align=center>$data[4]</td>";
      echo "</tr>";
      }
      echo "</table>";
      ?>





      share|improve this answer





















      • 7





        Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

        – Amal Murali
        Apr 23 '14 at 21:57











      • Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

        – user3816325
        May 19 '16 at 3:50











      • @user3816325 check your server. I believe your server isnt running.

        – prakashchhetri
        Sep 10 '16 at 13:23
















      53














      For retrieving data using Ajax+jQuery, you must write the following code:



       <html>
      <script type="text/javascript" src="jquery-1.3.2.js"> </script>

      <script type="text/javascript">

      $(document).ready(function() {

      $("#display").click(function() {

      $.ajax({ //create an ajax request to display.php
      type: "GET",
      url: "display.php",
      dataType: "html", //expect html to be returned
      success: function(response){
      $("#responsecontainer").html(response);
      //alert(response);
      }

      });
      });
      });

      </script>

      <body>
      <h3 align="center">Manage Student Details</h3>
      <table border="1" align="center">
      <tr>
      <td> <input type="button" id="display" value="Display All Data" /> </td>
      </tr>
      </table>
      <div id="responsecontainer" align="center">

      </div>
      </body>
      </html>


      For mysqli connection, write this:



      <?php 
      $con=mysqli_connect("localhost","root","");
      if (!$con)
      {
      die('Could not connect: ' . mysqli_error());
      }
      ?>


      For displaying the data from database, you must write this :



      <?php
      include("connection.php");
      mysqli_select_db("samples",$con);
      $result=mysqli_query("select * from student",$con);

      echo "<table border='1' >
      <tr>
      <td align=center> <b>Roll No</b></td>
      <td align=center><b>Name</b></td>
      <td align=center><b>Address</b></td>
      <td align=center><b>Stream</b></td></td>
      <td align=center><b>Status</b></td>";

      while($data = mysqli_fetch_row($result))
      {
      echo "<tr>";
      echo "<td align=center>$data[0]</td>";
      echo "<td align=center>$data[1]</td>";
      echo "<td align=center>$data[2]</td>";
      echo "<td align=center>$data[3]</td>";
      echo "<td align=center>$data[4]</td>";
      echo "</tr>";
      }
      echo "</table>";
      ?>





      share|improve this answer





















      • 7





        Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

        – Amal Murali
        Apr 23 '14 at 21:57











      • Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

        – user3816325
        May 19 '16 at 3:50











      • @user3816325 check your server. I believe your server isnt running.

        – prakashchhetri
        Sep 10 '16 at 13:23














      53












      53








      53







      For retrieving data using Ajax+jQuery, you must write the following code:



       <html>
      <script type="text/javascript" src="jquery-1.3.2.js"> </script>

      <script type="text/javascript">

      $(document).ready(function() {

      $("#display").click(function() {

      $.ajax({ //create an ajax request to display.php
      type: "GET",
      url: "display.php",
      dataType: "html", //expect html to be returned
      success: function(response){
      $("#responsecontainer").html(response);
      //alert(response);
      }

      });
      });
      });

      </script>

      <body>
      <h3 align="center">Manage Student Details</h3>
      <table border="1" align="center">
      <tr>
      <td> <input type="button" id="display" value="Display All Data" /> </td>
      </tr>
      </table>
      <div id="responsecontainer" align="center">

      </div>
      </body>
      </html>


      For mysqli connection, write this:



      <?php 
      $con=mysqli_connect("localhost","root","");
      if (!$con)
      {
      die('Could not connect: ' . mysqli_error());
      }
      ?>


      For displaying the data from database, you must write this :



      <?php
      include("connection.php");
      mysqli_select_db("samples",$con);
      $result=mysqli_query("select * from student",$con);

      echo "<table border='1' >
      <tr>
      <td align=center> <b>Roll No</b></td>
      <td align=center><b>Name</b></td>
      <td align=center><b>Address</b></td>
      <td align=center><b>Stream</b></td></td>
      <td align=center><b>Status</b></td>";

      while($data = mysqli_fetch_row($result))
      {
      echo "<tr>";
      echo "<td align=center>$data[0]</td>";
      echo "<td align=center>$data[1]</td>";
      echo "<td align=center>$data[2]</td>";
      echo "<td align=center>$data[3]</td>";
      echo "<td align=center>$data[4]</td>";
      echo "</tr>";
      }
      echo "</table>";
      ?>





      share|improve this answer















      For retrieving data using Ajax+jQuery, you must write the following code:



       <html>
      <script type="text/javascript" src="jquery-1.3.2.js"> </script>

      <script type="text/javascript">

      $(document).ready(function() {

      $("#display").click(function() {

      $.ajax({ //create an ajax request to display.php
      type: "GET",
      url: "display.php",
      dataType: "html", //expect html to be returned
      success: function(response){
      $("#responsecontainer").html(response);
      //alert(response);
      }

      });
      });
      });

      </script>

      <body>
      <h3 align="center">Manage Student Details</h3>
      <table border="1" align="center">
      <tr>
      <td> <input type="button" id="display" value="Display All Data" /> </td>
      </tr>
      </table>
      <div id="responsecontainer" align="center">

      </div>
      </body>
      </html>


      For mysqli connection, write this:



      <?php 
      $con=mysqli_connect("localhost","root","");
      if (!$con)
      {
      die('Could not connect: ' . mysqli_error());
      }
      ?>


      For displaying the data from database, you must write this :



      <?php
      include("connection.php");
      mysqli_select_db("samples",$con);
      $result=mysqli_query("select * from student",$con);

      echo "<table border='1' >
      <tr>
      <td align=center> <b>Roll No</b></td>
      <td align=center><b>Name</b></td>
      <td align=center><b>Address</b></td>
      <td align=center><b>Stream</b></td></td>
      <td align=center><b>Status</b></td>";

      while($data = mysqli_fetch_row($result))
      {
      echo "<tr>";
      echo "<td align=center>$data[0]</td>";
      echo "<td align=center>$data[1]</td>";
      echo "<td align=center>$data[2]</td>";
      echo "<td align=center>$data[3]</td>";
      echo "<td align=center>$data[4]</td>";
      echo "</tr>";
      }
      echo "</table>";
      ?>






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 21 '17 at 11:21









      Community

      11




      11










      answered Jun 3 '13 at 10:24









      Neha GandhiNeha Gandhi

      69155




      69155








      • 7





        Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

        – Amal Murali
        Apr 23 '14 at 21:57











      • Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

        – user3816325
        May 19 '16 at 3:50











      • @user3816325 check your server. I believe your server isnt running.

        – prakashchhetri
        Sep 10 '16 at 13:23














      • 7





        Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

        – Amal Murali
        Apr 23 '14 at 21:57











      • Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

        – user3816325
        May 19 '16 at 3:50











      • @user3816325 check your server. I believe your server isnt running.

        – prakashchhetri
        Sep 10 '16 at 13:23








      7




      7





      Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

      – Amal Murali
      Apr 23 '14 at 21:57





      Just a note: There is no more support for mysql_* functions, they are officially deprecated, no longer maintained and will be removed in the future. You should update your code with PDO or MySQLi to ensure the functionality of your project in the future.

      – Amal Murali
      Apr 23 '14 at 21:57













      Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

      – user3816325
      May 19 '16 at 3:50





      Hello Guys, I tried above code, but its returning full display file data along with php. Please can you let me know what can be issue. I am .net developer just working on php.

      – user3816325
      May 19 '16 at 3:50













      @user3816325 check your server. I believe your server isnt running.

      – prakashchhetri
      Sep 10 '16 at 13:23





      @user3816325 check your server. I believe your server isnt running.

      – prakashchhetri
      Sep 10 '16 at 13:23













      4
















      You can't return ajax return value. You stored global variable store your return values after return.

      Or Change ur code like this one.



      AjaxGet = function (url) {
      var result = $.ajax({
      type: "POST",
      url: url,
      param: '{}',
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      success: function (data) {
      // nothing needed here
      }
      }) .responseText ;
      return result;
      }








      share|improve this answer
























      • without Json i have to do.

        – Ravi
        May 23 '13 at 7:59











      • @RaviParmar change datatype "html".This is for example.

        – Mariselvam Panneerselvam
        May 23 '13 at 8:49


















      4
















      You can't return ajax return value. You stored global variable store your return values after return.

      Or Change ur code like this one.



      AjaxGet = function (url) {
      var result = $.ajax({
      type: "POST",
      url: url,
      param: '{}',
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      success: function (data) {
      // nothing needed here
      }
      }) .responseText ;
      return result;
      }








      share|improve this answer
























      • without Json i have to do.

        – Ravi
        May 23 '13 at 7:59











      • @RaviParmar change datatype "html".This is for example.

        – Mariselvam Panneerselvam
        May 23 '13 at 8:49
















      4












      4








      4









      You can't return ajax return value. You stored global variable store your return values after return.

      Or Change ur code like this one.



      AjaxGet = function (url) {
      var result = $.ajax({
      type: "POST",
      url: url,
      param: '{}',
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      success: function (data) {
      // nothing needed here
      }
      }) .responseText ;
      return result;
      }








      share|improve this answer















      You can't return ajax return value. You stored global variable store your return values after return.

      Or Change ur code like this one.



      AjaxGet = function (url) {
      var result = $.ajax({
      type: "POST",
      url: url,
      param: '{}',
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      async: false,
      success: function (data) {
      // nothing needed here
      }
      }) .responseText ;
      return result;
      }









      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 23 '13 at 7:25









      Mariselvam PanneerselvamMariselvam Panneerselvam

      10619




      10619













      • without Json i have to do.

        – Ravi
        May 23 '13 at 7:59











      • @RaviParmar change datatype "html".This is for example.

        – Mariselvam Panneerselvam
        May 23 '13 at 8:49





















      • without Json i have to do.

        – Ravi
        May 23 '13 at 7:59











      • @RaviParmar change datatype "html".This is for example.

        – Mariselvam Panneerselvam
        May 23 '13 at 8:49



















      without Json i have to do.

      – Ravi
      May 23 '13 at 7:59





      without Json i have to do.

      – Ravi
      May 23 '13 at 7:59













      @RaviParmar change datatype "html".This is for example.

      – Mariselvam Panneerselvam
      May 23 '13 at 8:49







      @RaviParmar change datatype "html".This is for example.

      – Mariselvam Panneerselvam
      May 23 '13 at 8:49













      2














      Please make sure your $row[1] , $row[2] contains correct value, we do assume here that 1 = Name , and 2 here is your Address field ?



      Assuming you have correctly fetched your records from your Records.php, You can do something like this:



      $(document).ready(function()
      {
      $('#getRecords').click(function()
      {
      var response = '';
      $.ajax({ type: 'POST',
      url: "Records.php",
      async: false,
      success : function(text){
      $('#table1').html(text);
      }
      });
      });

      }


      In your HTML



      <table id="table1"> 
      //Let jQuery AJAX Change This Text
      </table>
      <button id='getRecords'>Get Records</button>


      A little note:



      Try learing PDO http://php.net/manual/en/class.pdo.php since mysql_* functions are no longer encouraged..






      share|improve this answer






























        2














        Please make sure your $row[1] , $row[2] contains correct value, we do assume here that 1 = Name , and 2 here is your Address field ?



        Assuming you have correctly fetched your records from your Records.php, You can do something like this:



        $(document).ready(function()
        {
        $('#getRecords').click(function()
        {
        var response = '';
        $.ajax({ type: 'POST',
        url: "Records.php",
        async: false,
        success : function(text){
        $('#table1').html(text);
        }
        });
        });

        }


        In your HTML



        <table id="table1"> 
        //Let jQuery AJAX Change This Text
        </table>
        <button id='getRecords'>Get Records</button>


        A little note:



        Try learing PDO http://php.net/manual/en/class.pdo.php since mysql_* functions are no longer encouraged..






        share|improve this answer




























          2












          2








          2







          Please make sure your $row[1] , $row[2] contains correct value, we do assume here that 1 = Name , and 2 here is your Address field ?



          Assuming you have correctly fetched your records from your Records.php, You can do something like this:



          $(document).ready(function()
          {
          $('#getRecords').click(function()
          {
          var response = '';
          $.ajax({ type: 'POST',
          url: "Records.php",
          async: false,
          success : function(text){
          $('#table1').html(text);
          }
          });
          });

          }


          In your HTML



          <table id="table1"> 
          //Let jQuery AJAX Change This Text
          </table>
          <button id='getRecords'>Get Records</button>


          A little note:



          Try learing PDO http://php.net/manual/en/class.pdo.php since mysql_* functions are no longer encouraged..






          share|improve this answer















          Please make sure your $row[1] , $row[2] contains correct value, we do assume here that 1 = Name , and 2 here is your Address field ?



          Assuming you have correctly fetched your records from your Records.php, You can do something like this:



          $(document).ready(function()
          {
          $('#getRecords').click(function()
          {
          var response = '';
          $.ajax({ type: 'POST',
          url: "Records.php",
          async: false,
          success : function(text){
          $('#table1').html(text);
          }
          });
          });

          }


          In your HTML



          <table id="table1"> 
          //Let jQuery AJAX Change This Text
          </table>
          <button id='getRecords'>Get Records</button>


          A little note:



          Try learing PDO http://php.net/manual/en/class.pdo.php since mysql_* functions are no longer encouraged..







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 23 '13 at 8:32

























          answered May 23 '13 at 8:26









          ÞawÞaw

          1,55021535




          1,55021535























              1














              $(document).ready(function(){
              var response = '';
              $.ajax({ type: "GET",
              url: "Records.php",
              async: false,
              success : function(text)
              {
              response = text;
              }
              });

              alert(response);
              });


              needs to be:



              $(document).ready(function(){

              $.ajax({ type: "GET",
              url: "Records.php",
              async: false,
              success : function(text)
              {
              alert(text);
              }
              });

              });





              share|improve this answer






























                1














                $(document).ready(function(){
                var response = '';
                $.ajax({ type: "GET",
                url: "Records.php",
                async: false,
                success : function(text)
                {
                response = text;
                }
                });

                alert(response);
                });


                needs to be:



                $(document).ready(function(){

                $.ajax({ type: "GET",
                url: "Records.php",
                async: false,
                success : function(text)
                {
                alert(text);
                }
                });

                });





                share|improve this answer




























                  1












                  1








                  1







                  $(document).ready(function(){
                  var response = '';
                  $.ajax({ type: "GET",
                  url: "Records.php",
                  async: false,
                  success : function(text)
                  {
                  response = text;
                  }
                  });

                  alert(response);
                  });


                  needs to be:



                  $(document).ready(function(){

                  $.ajax({ type: "GET",
                  url: "Records.php",
                  async: false,
                  success : function(text)
                  {
                  alert(text);
                  }
                  });

                  });





                  share|improve this answer















                  $(document).ready(function(){
                  var response = '';
                  $.ajax({ type: "GET",
                  url: "Records.php",
                  async: false,
                  success : function(text)
                  {
                  response = text;
                  }
                  });

                  alert(response);
                  });


                  needs to be:



                  $(document).ready(function(){

                  $.ajax({ type: "GET",
                  url: "Records.php",
                  async: false,
                  success : function(text)
                  {
                  alert(text);
                  }
                  });

                  });






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited May 23 '13 at 8:29

























                  answered May 23 '13 at 8:15









                  gitaarikgitaarik

                  20.5k57176




                  20.5k57176

















                      protected by Community Feb 19 '14 at 5:43



                      Thank you for your interest in this question.
                      Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                      Would you like to answer one of these unanswered questions instead?



                      Popular posts from this blog

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks