Tags created dynamically with jQuery disappear after submitting my form

My page dynamically creates rows using jQuery, but when I refresh the form, the rows do not work.

How to save dynamically created jquery controls in MVC?

This is the basic details page, I am creating the detailed invoices page. In detail, there is a button that, when clicked on, displays a dialog box asking for detailed information. After clicking ok in the dialog box, I add a new part to the details table using jQuery. The problem is updating the page, the dynamically created line disappears.

+3
source share
5 answers

Internet has no status

, JavaScript , - . , . , .

Ajax

JavaScript , , jQuery , ajax .

jQuery AJAX library. jQuery. -, .

Ajax jQuery

, , ajax, ​​:

$.ajax({
  url: 'ajax/add_row.html?user_id=100&data=new-data',
  success: function(data) {
    alert('Adding of the row was acknowledged.');
  }
});

, ajax/add_row.html, , . , .

, , , script post.

+5

"ok" , , JQuery AJAX methods, , , , , , .

.

$('#okButton').click(function(){
  //Add row

  var data = {
    detailName: $('#detailName').val(),
    detailInfo: $('#detailInfo').val()
  };

  $.ajax({
    type: "POST",
    url: "controller/AddDetail",
    data: data,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(xml, ajaxStatus) {
    // whatever you want here
    }
  });
});

public ActionResult AddDetail(string detailName, string detailInfo)
{
  //Save detail
}
+2

. jquery . . , , , (, DynamicObjects [0].Value1, DynamicObjects [0].Value2, DynamicObjects [1].Value1, DynamicObjects [1].Value2...)

IEnumerable<DynamicObject> DynamicObjects{get;set;}

DynamicObject Value1 Value2.

, .

public ActionResult Index(MyModelClass form)
{
// do something
return View(form);
}

DynamicObjects arrey.

?

+1

ajax ?

, , dom, javascript/jquery.

0

? , , /. , Ajax, .

0

Source: https://habr.com/ru/post/1730137/


All Articles