This time I will show you how to solve the problem of page crash caused by data parameter error in ajax. What are the solutions to the page crash caused by data parameter error in ajax? What are the practical cases below? Let’s take a look. .
Today I was going to send the data of one row of the selected table to the backend through ajax, but the website did crash. The code is as follows:$('.icon-edit').click(function (event) { 这是一个按钮 o=$('.icon-edit').index($(this))+1; edit.style.display='block'; //console.log('$(this)',$(this).parent().parent()); let message=$(this).parent().parent(); $("#non").val(message.children('td:eq(0)').html()); $("#name").val(message.children('td:eq(1)').html()); $("#sex").val(message.children('td:eq(2)').html()); $("#age").val(message.children('td:eq(3)').html()); $("#xueyuan").val(message.children('td:eq(4)').html()); $("#grade").val(message.children('td:eq(5)').html()); $("#phone").val(message.children('td:eq(6)').html()); $("#room").val(message.children('td:eq(7)').html()); l=message.children('td:eq(0)').html(); }); $('#ok').click(function () { //event.stopImmediatePropagation(); let text=$('table'); id=$('#non').val(); username=$('#name').val(); sex=$('#sex').val(); age=$('#age').val(); institute=$('#xueyuan').val(); grade=$('#grade').val(); phone=$('#phone').val(); hlbhl=$('#room').val() text.find("tr:eq("+o+")").children('td:eq(0)').text(id); text.find("tr:eq("+o+")").children('td:eq(1)').text(username); text.find("tr:eq("+o+")").children('td:eq(2)').text(sex); text.find("tr:eq("+o+")").children('td:eq(3)').text(age); text.find("tr:eq("+o+")").children('td:eq(4)').text(institute); text.find("tr:eq("+o+")").children('td:eq(5)').text(grade); text.find("tr:eq("+o+")").children('td:eq(6)').text(phone); text.find("tr:eq("+o+")").children('td:eq(7)').text(hlbhl); $.ajax({ type: "POST", url: "doAction2.php",//请求的后台地址 data: { non:o, id: id, username: username, sex: sex, age: age, institute: institute, grade: grade, phone: phone, hlbhl: hlbhl },//前台传给后台的参数 dataType: "json", ansync: true, ContentType: "application/json; charset=utf-8", success: function (msg) {//msg:返回值 a=2; console.log(a); } }); edit.style.display='none'; });
modify the content of the table grid and click the OK button ($('#ok')) to overwrite the form data with the data of the previously clicked row to achieve the purpose of modifying the table. When OK is clicked, ajax is triggered. ,
Send the modified data to the backend, get the data and update the database.
id=text.find("tr:eq("+o+")").children('td:eq(0)').text(id); username=text.find("tr:eq("+o+")").children('td:eq(1)').text(username); sex=text.find("tr:eq("+o+")").children('td:eq(2)').text(sex); age=text.find("tr:eq("+o+")").children('td:eq(3)').text(age); institute=text.find("tr:eq("+o+")").children('td:eq(4)').text(institute); grade=text.find("tr:eq("+o+")").children('td:eq(5)').text(grade); phone=text.find("tr:eq("+o+")").children('td:eq(6)').text(phone); hlbhl=text.find("tr:eq("+o+")").children('td:eq(7)').text(hlbhl); $.ajax({ type: "POST", url: "doAction2.php",//请求的后台地址 data: { non:o, id: id, username: username, sex: sex, age: age, institute: institute, grade: grade, phone: phone, hlbhl: hlbhl },//前台传给后台的参数 dataType: "json", ansync: true, ContentType: "application/json; charset=utf-8", success: function (msg) {//msg:返回值 a=2; console.log(a); } }); edit.style.display='none'; });
string or the like, but a n.fn.init [td, prevObject: n.fn.init(1), context: document], Due to my carelessness and little understanding of the situations that caused ajax errors, I found out the cause after reading the code for a long time. At first I thought it would not be caused by parameters,
Detailed explanation of the steps to implement full-screen scrolling plug-in in ES6
Summary of how to use watch in Vue
The above is the detailed content of How to solve the problem of page crash due to data parameter error in ajax. For more information, please follow other related articles on the PHP Chinese website!