如何在不使用表单元素的情况下将div内容添加到mysql

如何在不使用表单元素的情况下将div内容添加到mysql

问题描述:

I want to save div content into mysql without using form and button means page should be opened in browser and it should send it's all div content to mysql table automatically.

here it is what i tried

var myVar = setInterval(function(){getElement()},5000);
function getElement()
{
  var iBody = $("#frametest").contents().find(".bx-viewport").html();
  document.getElementById("demo").innerHtml=iBody;
  alert(iBody);
}

i want this demo div to be saved in mysql

我想将div内容保存到mysql而不使用表单和按钮意味着页面应该在浏览器中打开它应该发送 这是所有div内容自动到mysql表。 p>

这里是我试过的 p>

  var myVar = setInterval(function(){getElement  ()},5000); 
 
函数getElement()
 {
 
 var iBody = $(“#frametest”)。contents()。find(“。bx-viewport”)。html(); 
文档。  getElementById(“demo”)。innerHtml = iBody; 
 alert(iBody); 
} 
  code>  pre> 
 
 

我希望这个demo div保存在mysql中 p> div>

If you don't want to use forms, I think AJAX is a great option.

var contents = $('#frametest').contents().find('.bx-viewport').html();
$.ajax({
  url: 'path/to/php/script',
  type: 'POST',
  data: {content: contents},
  success: function() {
    // do something after sending data
  }
});

This will send contents to the php script defined in the url property of the AJAX call as a POST request, and in the php script you can use the normal thing you'd do for saving it in MySQL.