I wrote this script FUNCTION to check whether the petty cash is already Set or not using AJAX...
function GetPettyCash() {
$.ajax({
type: 'GET',
url: '@Url.Action("CashSet", "POS")',
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data["CashSetIn"] == "true") {
alert(data["CashSetAmount"]);
return true;
}
else {
alert(data["CashSetIn"]);
return false;
}
},
error: function (req, status, errorObj) {
alert(errorObj.toString());
return false;
}
});
}
I Wrote this Controller for my Ajax Calls:
[HttpGet]
public JsonResult CashSet()
{
Login login = new Login();
login.CheckPettyCash();
if (login.CashInSet == true)
{
return Json(new
{
CashSetIn = "true",
CashSetAmount = login.CashInAmount
},JsonRequestBehavior.AllowGet);
}
else
{
return Json(new
{
CashSetIn = "false",
CashSetAmount = "0"
}, JsonRequestBehavior.AllowGet);
}
}
My Controller returns this JSON:
{"CashSetIn":"true","CashSetAmount":1000}
But my Function in the JS script always returns undefined... Any suggestion on how to fix this?
I tried testing it:
alert(data["CashSetAmount"]);
//the Result: 1000
alert(data["CashSetIn"]);
//the Result: true
alert(data);
//the Result: [object Object]
alert(data)insidesuccess: function (data){ans see what u get. Can u share that? do you get any data?login.CashInAmountdefined atCashSetAmount = login.CashInAmount?login.CashInAmountis defined atlogin.CheckPettyCash(); We've been using DLL Library