I am working with a jQuery-function to trigger an ajax request on click. However, I don't get a result though the script should send a value via post-method. It looks like the PHP-script doesn't receive the value, but probably the problem is elsewhere.
Maybe somebody can tell me where the problem is.
doClick = function (sender){
var jid = sender.id;
if ($(window).width() < 768) {
$('.jwin').addClass('order-md-1').removeClass('order-md-2').removeClass('d-none');
$('.jobs').addClass('order-md-2').removeClass('order-md-1').removeClass('d-block').addClass('d-none');
var ink = document.getElementById('ajax').value;
$.ajax({
url:"get_job.php",
method:"POST",
data:{jid:jid},
cache:false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success:function(data)
{
//console.log(data.success);
if(data.success == TRUE)
{
//$('#ajax').text(data.nurl);
$('#title').text(data.title);
$('#crp').text(data.compnme);
$('#descript').html(data.jtxt);
$('#jadoci').text(data.city);
$('#jadost').text(data.state);
$('#connx1').css("display", "inline");
$('#connx2').css("display", "inline");
$('#applylink').css("display","block");
$('#applylink').attr('href',"links?jid="+jid);
if(data.url==''){
$('#applylink').css("display","none");
}
}else{
// Fade in
alert(data.success);
}
}
});
$('#returnmobile').append("<a href=''>"+jid+"</a>");
}
else {
$.ajax({
url:"get_job.php",
method:"POST",
data:{jid:jid},
cache:false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success:function(data)
{
//console.log(data.success);
if(data.success == TRUE)
{
//$('#ajax').text(data.nurl);
$('#title').text(data.title);
$('#descript').html(data.jtxt);
if(data.company==0){
$('#crp').text("Agent");
}
else{
$('#crp').text(data.compnme);
$('#crp').attr('href','company?id='+data.company)
}
$('#jadoci').text(data.city);
$('#jadost').text(data.state);
$('#connx1').css("display", "inline");
$('#connx2').css("display", "inline");
$('#applylink').css("display","block");
$('#applylink').attr('href',"links?jid="+jid);
if(data.url==''){
$('#applylink').css("display","none");
}
}else{
// Fade in
alert(data.success);
}
}
});
//alert('More than 960');
}
};
And the PHP-code:
require "config.php";
$jid = $_POST["jid"];
$ipa = $_SERVER['REMOTE_ADDR'];
$query = $con->query("SELECT jla.title AS title, jla.summary AS jtxt, jla.city AS city, jla.state AS state, jla.company AS corp, c.name AS company, jla.url AS url, jla.id AS coid FROM jobs jla LEFT JOIN companies c ON c.id = jla.company WHERE jla.id = $jid");
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$output = array('success'=>TRUE,
'nurl'=>("<b>Does</b> it work? Yes!"),
'company'=>$row['corp'],
'compnme'=>$row['company'],
'title'=>$row['title'],
'city'=>$row['city'],
'state'=>$row['state'],
'coid'=>$row['coid'],
'url'=>$row['url'],
'jtxt'=>$row['jtxt']);
$quip0 = $con->query("SELECT * FROM clicks WHERE ip = '$ipa' AND job_id = '$jid'");
if($quip0->num_rows < 1){
$quip1 = "INSERT INTO clicks (ip, job_id) VALUES ('$ipa','$jid')";
if ( $con->query($quip1) === TRUE) {
echo json_encode($output,JSON_FORCE_OBJECT);
}
}
else {
echo json_encode($output,JSON_FORCE_OBJECT);
}
}
}
Again: the result I receive seems to be empty. Even in the inspect-mode in Chrome I don't see values that I'd expect, making me suspicious that the $jid value wouldn't be delivered correctly. Btw: sender.id works so far. I used to test this.