Hello!

I have an application on Spring MVC and so on the page there is a table with academic subjects and a form for adding a new subject. When you add a new item, it appears in the list without rebooting. But I have an error when inserting a link to the side of the subject name link to edit and delete

Script:

<script> $(document).ready(function () { $('#saveSubject').submit(function (e) { $.post('/university/subjectAdd', $(this).serialize(), function (subject) { $('#subjectsTableResponse').last().append( '<tr>' + '<td align=\"center\">' + subject.title + '</td>' + '<td align=\"center\">' + '<a href=\"c:url value=\'/subject/update/{'+subject.id+'}\'/>' + Редактировать + '</a>'+'</td>'+ '<td align=\"center\">' + '<a href=\"c:url value=\'/subject/delete/{'+subject.id+'}\'/>' + Удалить + '</a>'+'</td>'+ '</tr>' ); }); }); }); 

The error in the browser is this:

 Uncaught ReferenceError: Редактировать is not defined 

But after reloading the page, everything is OK, I suspect that something is wrong with escaping characters in the link, because if you remove the addition of links and leave just the names of the items, then everything is OK without errors. I want ajax to insert this link in the answer "> Delete How to solve this problem?

  • one
    The words Edit and Delete must be in quotes so that they are strings. Now you have them js perceives as variables. So just on the sides of these words, take away the '+ that would be ..... \' /> Edit </a> .... - Andy
  • Andy, first - thanks for the reply. The second one has removed the quotes on the sides, but, unfortunately, now the record with empty fields is added to the table, where it should be edited and deleted. Here is my link that I need ajax to insert into the table when adding a new record - <a href="<c:url value='/subject/delete/${subject.id}' /> "> Delete </ a > do not tell me how to correctly indicate it in the response so that it is displayed correctly? - CopKubar
  • Plus, after updating the page, links begin to display correctly - CopKubar

1 answer 1

Thank you all, the problem was in inattention, I forgot to add - ">