Now when using ajax to interact with the backend, in the data part of ajax, the method used is to bind the jq nodes to the output parameters one by one (as shown in the figure). This method can handle it when there are few parameters, but when there are too many parameters, both coding and maintenance efficiency will become lower. When writing the data part of ajax, how can we optimize it better?
$.ajax({ url: "/openapi/test.json", dataType: "json", type: "post", formTypeData: true, data: { "keywords": $(".fmc-plate").attr("data-actioncontent"), "openId": localOpenId, "msgType": Msg.msgTypeElem, 'msgBody': Msg.msgBodyElem, "enable": true, "type": 3, "replyType": 3 }, success: function (json) { data = json.data; if (json.success == false) { noty({ text: "保存失败,请检查是否填入所有所需数据", layout: "top", timeout: 3000, type: "error" }); return false; } else { noty({ text: "保存成功", layout: "top", timeout: 1000, type: "success" }); $(".fmc-plate").remove(); $noty.close(); } } });
It’s easy to use jquery, just use serialize()
html
js