I am creating a web application in yii where I am sending ajax request to update the database.
The application worked for the first time and after that it threw the following error.
Here the data is getting updated in the database but I am not getting the response back.
POST http://localhost:8080/simplerAP/index.php?r=site/UpdateRates 500 (Internal Server Error)
k.cors.a.crossDomain.send @ jQuery-2.1.4.min.js:4
n.extend.ajax @ jQuery-2.1.4.min.js:4
saveRates @ index.php?r=site/tariffcard:528
btn.onclick @ index.php?r=site/tariffcard:499
My JS code is as follows
<script type="text/javascript">
function enableTextBox(regularId, urgentId, btnId)
{
//alert(regularId + " " + urgentId + " " + btnId);
document.getElementById(regularId).removeAttribute("disabled");
document.getElementById(urgentId).removeAttribute("disabled");
//document.getElementById(regularId).className = "form-control";
//document.getElementById(urgentId).className = "form-control";
var btnSpan = document.getElementById(btnId);
while(btnSpan.firstChild)
{
btnSpan.removeChild(btnSpan.firstChild);
}
var btn = document.createElement("INPUT");
btn.type = "button";
btn.value = "Save";
btn.className = "btn btn-primary";
btn.id = btnId;
btn.onclick = function(){ saveRates(this.id, document.getElementById(regularId).value, document.getElementById(urgentId).value)};
btnSpan.appendChild(btn);
}
function saveRates(btnId, regularValue, urgentValue)
{
//alert(btnId + " " + regularValue + " " + urgentValue);
var clothType = btnId.substring(0, btnId.indexOf("-"));
//alert(clothType);
var tariffCardType = btnId.substring(btnId.indexOf("-")+1, btnId.indexOf("-", btnId.indexOf("-")+1));
//alert(tariffCardType);
var jobTypeCode = btnId.substring(btnId.indexOf("-", btnId.indexOf("-")+1)+1, btnId.length);
if(jobTypeCode == "I")
{
jobType = "iron";
}
if(jobTypeCode == "WI")
{
jobType = "washiron";
}
if(jobTypeCode == "D")
{
jobType = "drycleaning";
}
//alert(jobType);
var newRegularRate = regularValue;
var newUrgentRate = urgentValue;
$.ajax
(
{
url:'/simplerAP/index.php?r=site/UpdateRates',
type:'post',
data:{tarifftardtype:tariffCardType, jobtype:jobType, clothtype:clothType, newregularrate:newRegularRate, newurgentrate:newUrgentRate},
success:function(data)
{
document.getElementById('demo').innerHTML = data;
},
cache:false}
);
}
</script>