0
보기 urlCreate 코드아약스 내부 서버 오류
$ajaxSaveTestGrid = Yii::$app->urlManager->createUrl('testgrid/ajaxsave');
이것은이
public function actionAjaxsave() {
$result = array();
$testGrid_name = $_GET['testGrid_name'];
$testGrid_qty = $_GET['testGrid_qty'];
$testGrid_price = $_GET['testGrid_price'];
$model = new Testgrid();
$model->name = $testGrid_name;
$model->price = $testGrid_price;
$model->qty = $testGrid_qty;
if ($model->save()) {
array_push($result, ['testgrid' => $model]);
$result = Json::encode($result);
echo $result;
} else {
echo 'error';
}
}
그것은 내부 서버 오류 발생 내 컨트롤러입니다
function saveRow(id, index) { if(id == 'tbl_testGrid') { save(id, index); } } function save(id, index) { var testGrid_name = $('#testGrid_name' + index).val(); var testGrid_qty = $('#testGrid_qty' + index).val(); var testGrid_price = $('#testGrid_price' + index).val(); var url = '$ajaxSaveTestGrid'; // alert(testGrid_name+testGrid_qty+testGrid_price); $.ajax({ type: 'GET', url: url, data: { testGrid_name:testGrid_name, testGrid_qty:testGrid_qty, testGrid_price:testGrid_price }, contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (response) { if(response == 'error') { alert('Fail to save! Please try again'); } else { $('#testGrid_name' + index).attr(\"disabled\",true); $('#testGrid_qty' + index).attr(\"disabled\",true); $('#testGrid_price' + index).attr(\"disabled\", true); $('#testGrid_save_button' + index).attr(\"class\", \"hidden\"); $('#testGrid_delete_button' + index).attr(\"class\", \"hidden\"); $('#testGrid_edit_button' + index).attr(\"class\", \"show\"); $('#hid_testGrid_id' + index).val(response[0].testgrid.id); $('html,body').animate({scrollTop: $('#btn_testGrid').offset().top}); } } }); }
내보기 아약스 코드
모델에 json Data를 저장하려고합니다.
문제를 해결 했습니까? – SilverFire