ajax - ajax laravel更新功能中的列不能为空
问题描述
大家好,我正在将我的更新值从 ajax 发送到我的更新函数。我收到错误,因为“列不能为空”
这是我发送 json 数据的输入:
<input type="text" id="jsonData" name="jsonData">
这是我的ajax表单:
function saveEditQtypeFile(edit_qtype_id)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
chk_EnumValuesValidation = chkEnumValuesValidation(isSoltion, stepCount);
if(!chk_EnumValuesValidation)
{
return false;
}
else
{
// Function to push "MainArray" in current Solution
pushVarMainArrayInThisSolution(isSoltion, var_main_arr.var_arr_values);
arr = ar;
var edit_qtype_id = $('#edit_qtype_id').val();
var qtype_name = $('#qtype_name').val();
var subject_list = $('#qtype_subject_id').val();
var ddl_topic_type = $('#qtype_topic_id').val();
var qtype_option = $('#qtype_option').val();
var jasondata = $('#jsonData').val();
var sort_order = $('#sort_order').val();
var sendInfo = {
'edit_qtype_id':edit_qtype_id,
'arr':arr,
'saveEditQtypeFile':1,
'qtype_name':qtype_name,
'qtype_subject_id':subject_list,
'qtype_topic_id':ddl_topic_type,
'qtype_option':qtype_option,
'qtype_json':jasondata,
'sort_order':sort_order
};
console.log('json',jasondata);
//return false;
//var loadQtypeInfo = JSON.stringify(sendInfo);
$.ajax({
url: "/eqtype-editor/update",
type: "POST",
data :sendInfo,
contentType: "application/x-www-form-urlencoded",
success: function(response)
{
alert('Your file is updated!');
window.location.href ="/eqtype-editor";
},
error: function (request, status, error)
{
alert('problem with updating record!!!');
},
complete: function()
{}
});
}
}
这是我的控制器:
public function update(Request $request, Qtype_editor $qtype_editor)
{
$qtype_editor = Qtype_editor::findOrFail($request->edit_qtype_id);
$qtype_editor->qtype_name = $request->input('qtype_name');
$qtype_editor->qtype_subject_id = $request->input('qtype_subject_id');
$qtype_editor->qtype_topic_id = $request->input('qtype_topic_id');
$qtype_editor->qtype_option = $request->input('qtype_option');
$qtype_editor->qtype_json = json_decode($request->input('jsonData'));
$qtype_editor->sort_order = $request->input('sort_order');
$qtype_editor->save();
return redirect()->route('eqtype-editor.index');
}
当我控制台时从 ajax 获取我的 json 数据..我收到错误,因为 qtype_json 不能为空。
谁能帮我在我想念它的地方。
提前致谢。
解决方案
您为数据使用了错误的密钥。
更改控制器中的行:
$qtype_editor->qtype_json = json_decode($request->input('jsonData'));
至
$qtype_editor->qtype_json = json_decode($request->input('qtype_json'));
它会起作用。
推荐阅读
- tensorflow - YOLO 的损失函数
- airflow - 基于数据库表的气流 DAG 调度
- nsis - 使用 nsDialog 的 listview 安装文件
- google-apps-marketplace - 同意屏幕上的图标 URL 与您主页上的图标不匹配
- sql - SQL - 仅访问特定列中结构值的第一行
- tags - Gitlab CI:仅为受保护分支上存在的标记提交运行管道作业
- function - 为什么我的代码中的 String.() -> Unit 与 (String) -> Unit 相同?
- git - 使用基于功能分支的 rebase 提交消息修改,然后合并到 master
- ios-simulator - 如何在 Iphone 中使用 frida 模拟触摸事件(已经越狱)
- strapi - 打开strapi / admin页面时如何修复404页面?