tags:

views:

33

answers:

2

I am calling a .php file in this code. In the file "fetchvalues.php", I am fetching results from the database and want to return the column values back to the calling JQuery function and display them on HTML controls of my page.

How to do so?

$(document).ready(function() {
    $("#Edit").click(function() {
        $.get('fetchvalues.php', null, function() {
            alert('reached'); 
        });
    });
});

Edited: Code: fetchvalues.php

<?PHP

 //Get selected row's RecordID column value
 $SelectedRowID = $_GET['UpdateRecordID'];
 //Open Connection
 $connection = mysql_connect("localhost:3306", "abcd", "abcd");
 mysql_select_db("pglobal", $connection);

 //Prepare query to retrieve results
 $FetchResultsQuery = "SELECT * FROM listing WHERE recordid=" . $SelectedRowID;

 try
 {
  $result = mysql_query($FetchResultsQuery);
  $row = mysql_fetch_row($result);
  if ($row)
  {
   $PostedDate = date('d.M.Y', strtotime($row[0]));
   $Places =  html_entity_decode($row[1]);
   $Company = html_entity_decode($row[2]);
   $Designation = html_entity_decode($row[3]);
   $ProjectDetails = html_entity_decode($row[4]);
   $DesiredCandidate = html_entity_decode($row[5]);
   $HRName = html_entity_decode($row[6]);
   $HRContact = html_entity_decode($row[7]);
   $Email = html_entity_decode($row[8]);

   $_SESSION['WorkMode'] = 'Edit';
   $_SESSION['DataToBeEdited'] = $PostedDate .'+'. $Places .'+'. $Company .'+'. $Designation .'+'. $ProjectDetails .'+'. $DesiredCandidate .'+'. $HRName .'+'. $HRContact .'+'. $Email;
  }
  else
  {
   $_SESSION['DataToBeEdited'] = "";
   return;
  }

 }
 catch(exception $err)
 {
  echo $err;
 }
?>
+1  A: 

If i could understand, you need back the response then:

$(document).ready(function(){
  $("#Edit").click(function(){
  $.get('fetchvalues.php', null, function(response){
  alert(response);
  });
  });
});
Sarfraz
Partially correct. I wrote: echo "<script type='text/javascript'>alert('level 1');</script>"; in fetchvalues.php. It is showing the entire above line in the alert window. Why it didn't execute the code in fetchvalues.php.
RPK
Any replaced $.get with $.getJSON and it worked.
RPK
@RPK: that is great to know :)
Sarfraz
A: 

You could generate JSON data, and handle it with jquery - also see the last of the examples at http://docs.jquery.com/Ajax/jQuery.get#urldatacallbacktype

zpon