I am a newbie in javascript,jquery,ajax. I have a problem with not working of my code. so well my codes and my work description is described below. Can someone help me please.
I have hotjobs.php file and hotjobsoutput.js file and api.php file. In hotjobs.php file my code is like:
Hotjobs.php:
<?php
$sql=mysql_query("select * from hotjob");
$count=mysql_num_rows($sql); if($count>0){ while
($result=mysql_fetch_array($sql)){?><tr><td><?php echo
$result['job_title'];?></td></tr><?php }}?>
Now I want to get a row datas from database when I click its job_title name i.e $result['job_title'] using ajax jquery.To do so I need to pass $result ['job_title']'s particular id to ajax jquery source code (hotjoboutput.js) so that the id could be passed to api.php file as ajax url parameter.
And my api.php file contains:
<?php
include("config.php");
$jobid=$_GET['jobid'];
$sql=mysql_query("select * from hotjobs where job_id='$jobid'");
$count=mysql_num_rows($sql);
if($count==1){
$result=mysql_fetch_array($sql);
}
echo json_encode($result);
?>
My hotjoboutput.js contains:
$function getrecord(id){
var jobid=id;
$.ajax({
url:'api.php?',
data:"jobid="+jobid,
dataType:'json',
success:function(data)
{
var jobtitle=data[1];
var refrence_no=data[2];
var company=data[3];
var country=data[4];
var salary=data[5];
var salaryincurrency=data[6];
var dutyhours=data[7];
var food=data[8];
var accomodation=data[9];
var medical=data[10];
var overtime=data[11];
var period=data[12];
var leavedays=data[13];
var joiningairticket=data[14];
var returnairticket=data[15];
var nofvaccancy=data[16];
var note=data[17];
$("#hotjoboutput").html("<p>vaccancy for "+jobtitle+"</p><table border=1px cellpadding=2px><tr><td>Refrence_no</td>td>"+Refrence_no+"</td></tr>
<tr><td>Company</td><td>"+company+"</td></tr>
<tr><td>Country</td><td>"+country+"</td></tr>
<tr><td>Salary</td><td>"+salary+"</td></tr>
<tr><td>Salary in Currency</td><td>"+salaryincurrency+"</td></tr>
<tr><td>Duty </td><td>"+dutyhours+"</td></tr>
<tr colspan=2>Terms and conditions</tr>
<tr><td>Food</td><td>"+food+"</td></tr>
<tr><td>Accomodation</td><td>"+accomodation+"</td></tr>
<tr><td>Medical</td><td>"+medical+"</td></tr>
<tr><td>Overtime</td><td>"+overtime+"</td></tr>
<tr><td>Period of contract</td><td>"+period+"</td></tr>
<tr><td>Leave</td><td>"+leavedays+"</td></tr>
<tr><td>Joining Air Ticket</td><td>"+joiningairticket+"</td></tr>
<tr><td>Return Air Ticket</td><td>"+returnairticket+"</td></tr>
<tr><td>No of vaccancy</td><td>"+nofvaccancy+"</td></tr>
<tr><td>Note</td><td>"+note+"</td></tr>
</table>");
}
});
});
I hope i'm clear with my question somehow. Please if anyone can help this guy!