#1 July 7, 2016 6:52am

Daydreamer
Member
Registered: July 7, 2016
Posts: 2

Cannot Access Request Array Using Ajax

Hi, So i'm currently working on a website that loads a container once a button is clicked and the content is loaded via an AJAX function. The problem is at the PHP side, I cannot access the variable i pass through the AJAX function through my REQUEST array. I'm not sure if it is a problem with big tree.But i really would appreciate some help.

  This is the button i use to call the function:
<div class="button-holder">
                    <button class="project-btn" data-id='<?=$id?>' onclick="getProject(<?=$id?>)">
                        <h3 class="btn-text">View Project</h3>
                        <h3 class="hide-reveal">&rarr;</h3>
                        <h3 class="button-pike"></h3>
                    </button>


     So this is my ajax function:
function getProject(id)
{
    var ajaxUrl='ajax/singleProject?id=' + id;
    $.ajax(ajaxUrl, {
        async: true, complete: getProjectComplete
    });
}

function getProjectComplete(xhr, status) {
    if (status == false)
    {
        return;
    }
    var obj = $.parseJSON(xhr.responseText);
    $('.pro-heading').html(obj.company);
    $('.pro-subtext').html(obj.project_heading + '(' + obj.start_date + ')');
    $('.pro-image').attr('src', obj.project_image);
    $('.pro-brief').html(obj.project_brief);
    $('.pro-details').html(obj.project_details);
    console.log(obj);
}


and this is my PHP function:
<?php
if (isset($_REQUEST['id']))
    $id = $_REQUEST['id'];
$obj = new Projects();
$single = $obj->get($id);
echo json_encode($single);
?>

Offline

#2 July 7, 2016 8:38am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 974

Re: Cannot Access Request Array Using Ajax

Have you verified that your singleProject.php file is being hit? If so, what do you get when you print_r($_REQUEST)?

Offline

#3 July 14, 2016 4:57am

Daydreamer
Member
Registered: July 7, 2016
Posts: 2

Re: Cannot Access Request Array Using Ajax

Yh it is being.but the actual problem was with the permissions on the file. I had created it in an IDE(Netbeans) and it seems it was given some restrictions. When i recreated it in a text editor...it worked just fine. Thank You.

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.