Jump to content

Relatively new to AJAX


bjacob

Recommended Posts

I am currently rewriting a corporate workflow from SharePoint into PHP/MySQL and I need to build an on-line approval process using AJAX and PHP. 

 

The basic logic flow is thus:

 

A new item which qualifies for this online approval triggers my JQuery module. 

 

The first JQuery function executes AJAX to execute a php script to build the shell of the approval record (works correctly as written) and then a second AJAX function sends a notification email to the approving/declining grouping.  The email contains 2 links - one to approve; the other to decline.  Depending on which link is clicked, another php script is executed to either approve or decline the record just built.  This step also works correctly.

 

A third AJAX request then executes.  Its purpose is to query the approved/declined record and pass the approval decision back to the user so they can complete the form. 

 

It is this third function which is not working.  FYI, all 3 of these AJAX request are set as async: false.  The first 2 requests are POSTS.  The third request has been tried as both a GET and a POST, but I end up with the same issue.

 

Below is the AJAX code for this third function, followed by the php script being called to query the approved/declined status result:

 

 

JQUERY module code:

 

    function CheckOFACapproval(number) {

var OFACresponse = 'Number=' + number;

alert(OFACresponse);

 

var request = $.ajax({

url: "http://eeiweb/eecore/php/Query-OFAC-Response.php",

type: "GET",

        data: OFACresponse,

dataType: "text",

async: false

});

request.fail(function(jqXHR, textStatus, errorThrown) {alert("Response: " + textStatus + " - " + errorThrown);});

request.done(function(data) {

var approvedecline = $(data.d);

 

    //if ((approvedecline == "Approved") || (approvedecline == "Declined")) {

var template = "<p>Approval: " + approvedecline + "</p>";

$('#OFACApprovalDialog').html(template);

$('#OFAC').val(approvedecline);

//};

});

    };

 

The JQuery AJAX request passes in a reference number to the Query-OFAC-Response.php module and is supposed to return the approvedecline variable from the PHP code (see below).  The request.done function fires when this request completes, but the value of the approvedecline variable is always [object Object]; iow, I don't think the value is getting set in the PHP's "echo $response" statement.  I am expecting the result to be passed back as text; the same as how the

input value is being passed.

 

PHP module code:

 

<?php

$dbhost = 'localhost:redacted';

$dbuser = 'root';

$dbpass = 'redacted';

$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn ){die('Could not connect: ' . mysql_error());}

 

mysql_select_db("ee_db");

 

$Number = $_GET['Number'];

 

$rc = 0;

 

$sql = "Select * From ANB_EE_OFAC Where Number = $Number Order By Created DESC LIMIT 1";

 

$result = mysql_query($sql, $conn);

 

while ($row = mysql_fetch_array($result)) {

$response = $row['ApproveDecline'];

};

 

$rc = mysql_errno();

 

echo $response;

 

mysql_free_result($result);

mysql_close($conn);

?>

 

Any idea what I'm doing wrong here?

Link to comment
Share on other sites

Update.  I ran my code thru Fiddler and my 3rd AJAX function is working correctly, so my issue is dereferencing the object in JQuery:

 

var approvedecline = $(data.d);

 

Anyone have any ideas how to extract the text property from $(data) or $(data.d)?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.