Having an issue with a returning an object loaded from an AJAX Jquery call using the .done parameter. Before returning the object to the calling function I am able to see the correctly loaded elements. However once shipped back it comes up undefined. I thought it was due to the asych nature of the call. I understand the .done should return a full completed call.
I'll wear maroon for a week if I can get a hand. Sorry the formatting is beat up. texags removes all the formatting. thanks in advance
The call is simply:
pcodeRec = loadPcodeData(currentPcode, pcodeRec);
The function is :
function loadPcodeData(currentPcode, pcodeRec){
var appUrl = get_BaseUrl();
var sendVar = currentPcode + ",pcode_table,prod_pcode";
// var sendVar = "mac,cust_table,cust_name";
var recReturned = "";
var lastRec = 0;
var recProcessed = "";
alert("beginning sendVar = " + sendVar + " appUrl = " + appUrl);
sendVar = "4250ART,pcode_table,prod_pcode"; //test param
$.ajax({
type: 'post',
url: appUrl + "ajax_sebms.php",
data:"q=" + sendVar,
complete: function(sendVar){ // this block displays all sql recs fitting the search
alert("in complete sendVar = " + sendVar);
}
})
.done(function( sendVar ) {
alert("in loadPcodeData sendVar= " + sendVar);
recReturned = sendVar;
lastRec = recReturned.search(">{") + 1; // find the begining of the jason
if (lastRec > 0) { //Last record clean off the junk and get the JSON
recProcessed = recReturned.substr(lastRec);
var pcodeRec = JSON.parse(recProcessed);
if (pcodeRec.prod_pcode == currentPcode) {
alert("prod_pcode = " + pcodeRec.prod_pcode + " currentPcode = " + currentPcode);
return(pcodeRec);
}
else {
alert("Warning the Pcode not found");
pcodeRec.prod_desc = "NF";
}
}
})
.fail(function( ) {
alert( "Sorry, there was a problem!" );
})
}
I'll wear maroon for a week if I can get a hand. Sorry the formatting is beat up. texags removes all the formatting. thanks in advance
The call is simply:
pcodeRec = loadPcodeData(currentPcode, pcodeRec);
The function is :
function loadPcodeData(currentPcode, pcodeRec){
var appUrl = get_BaseUrl();
var sendVar = currentPcode + ",pcode_table,prod_pcode";
// var sendVar = "mac,cust_table,cust_name";
var recReturned = "";
var lastRec = 0;
var recProcessed = "";
alert("beginning sendVar = " + sendVar + " appUrl = " + appUrl);
sendVar = "4250ART,pcode_table,prod_pcode"; //test param
$.ajax({
type: 'post',
url: appUrl + "ajax_sebms.php",
data:"q=" + sendVar,
complete: function(sendVar){ // this block displays all sql recs fitting the search
alert("in complete sendVar = " + sendVar);
}
})
.done(function( sendVar ) {
alert("in loadPcodeData sendVar= " + sendVar);
recReturned = sendVar;
lastRec = recReturned.search(">{") + 1; // find the begining of the jason
if (lastRec > 0) { //Last record clean off the junk and get the JSON
recProcessed = recReturned.substr(lastRec);
var pcodeRec = JSON.parse(recProcessed);
if (pcodeRec.prod_pcode == currentPcode) {
alert("prod_pcode = " + pcodeRec.prod_pcode + " currentPcode = " + currentPcode);
return(pcodeRec);
}
else {
alert("Warning the Pcode not found");
pcodeRec.prod_desc = "NF";
}
}
})
.fail(function( ) {
alert( "Sorry, there was a problem!" );
})
}