I'm having trouble getting the expected result.
I have the following jQuery script:
// obj is the return result of another query
jQuery.post("mypath/include/jquery_bll.php", { instance: 'controllAccess', brandID: obj.id },
function(data)
{
if (jQuery('#brand_selectList').length == 0)
{
if (data == "Locked")
{
jQuery('#countryListBox').attr('disabled','true');
}
}
}, "text");
So what this does, is to disable select box if return result = "Locked".
Here is my PHP code that returns the result:
function controllBrandRelation($dal)
{
// Get label data.
$result = $dal->getRowByValue('myTable','id', $_POST['someID']);
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
$ownerID = $row["fk_userID"];
}
}
if(!empty($ownerID))
echo 'Locked';
else
echo 'Open';
}
This will return 'Locked' if $ownerID has some values.
This is my problem:
If I do an alert(data.length)
, I get the result 72. I really should be getting 6, which is the number of characters in the word 'Locked'.
jQuery.post("mypath/include/jquery_bll.php", { instance: 'controllAccess', brandID: obj.id },
function(data)
{
alert(data.length);
}
If I do an alert(jQuery.trim(data).length)
, I get the correct value.
But whatever I do, I'm not able to get inside this IF test:
if (data == "Locked")
{
jQuery('#countryListBox').attr('disabled','true');
}
Why is data not equal "Locked"?
I've tested with both the trimmed and untrimed version.
UPDATE
I've managed to get it working by changing return results from text to json.
So now I check on if (data.status == "locked")
, and it works fine.
But I really would like to know how the return results for text is 76 characters long, when it should be 6. And why I'm not able to match/test the result.