我正在尝试使用 php 在幕后运行 jQuery 脚本。它基本上会使用 jQuery (works) 获取 div 的内容,然后使用 ajax (works) 调用脚本,但我需要调用 php 的 ajax 脚本将 vars 发送到 php,这样我就可以保存内容。
这是代码:
<script>
$( document ).ready(function() {
$( ".tweets" ).click(function() {
var htmlString = $( this ).html();
tweetUpdate(htmlString);
});
});
</script>
<script>
function tweetUpdate(htmlString)
{
$.ajax({
type: "POST",
url: 'saveTweets.php',
data: htmlString,
success: function (data) {
// this is executed when ajax call finished well
alert('content of the executed page: ' + data);
},
error: function (xhr, status, error) {
// executed if something went wrong during call
if (xhr.status > 0) alert('got error: ' + status); // status 0 - when load is interrupted
}
});
}
</script>
和我的 saveTweets.php 代码
<?
// SUPPOSED TO receive html conents called htmlString taken from a div
// and then I will write this code to a file with php and save it.
echo $_POST[htmlString];
?>