Javascript html动态div替换jquery
所以我在witts端,我正在升级一个移动网站,从一个定制的用户构建主题升级到使用新的jquerymobile主题 问题是该站点有一个聊天室部分,它利用以下代码不断地用另一个包含新消息的php文件的内容更新聊天消息divJavascript html动态div替换jquery,javascript,jquery,css,jquery-mobile,Javascript,Jquery,Css,Jquery Mobile,所以我在witts端,我正在升级一个移动网站,从一个定制的用户构建主题升级到使用新的jquerymobile主题 问题是该站点有一个聊天室部分,它利用以下代码不断地用另一个包含新消息的php文件的内容更新聊天消息div <script type="text/javascript" src="../jquery.min.js"></script> <script type="text/javascript"> // jQuery Document
<script type="text/javascript" src="../jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function() {
});
function loadLog(){
$.ajax({
url: "chattextd.php?room=<?php echo $roomid; ?>&sid=<?php echo $sid; ?>",
cache: false,
success: function(html){
(document.getElementById("chatbox")).innerHTML = "";
$("#chatbox").html(html); //Insert chat log into the #chatbox div
}
});
}
function sendData(){
$.post ('chathandlerb.php',{message: form.message.value,roomid: form.roomid.value,cmode: form.cmode.value,sid: form.sid.value});
$.ajax({
url: "chattextd.php?room=<?php echo $roomid; ?>&sid=<?php echo $sid; ?>",
cache: false,
success: function(html){
(document.getElementById("chatbox")).innerHTML = "";
$("#chatbox").html(html); //Insert chat log into the #chatbox div
$("#message").val("");
loadLog();
}
});
}
$('#form').submit(function() {
// submit the form
sendData();
return false;
});
loadLog();
setInterval (loadLog, 5000);
</script>
//jQuery文档
$(文档).ready(函数(){
});
函数loadLog(){
$.ajax({
url:“chattextd.php?room=&sid=”,
cache:false,
成功:函数(html){
(document.getElementById(“chatbox”).innerHTML=“”;
$(“#chatbox”).html(html);//将聊天日志插入#chatbox div
}
});
}
函数sendData(){
$.post('chathandlerb.php',{message:form.message.value,roomid:form.roomid.value,cmode:form.cmode.value,sid:form.sid.value});
$.ajax({
url:“chattextd.php?room=&sid=”,
cache:false,
成功:函数(html){
(document.getElementById(“chatbox”).innerHTML=“”;
$(“#chatbox”).html(html);//将聊天日志插入#chatbox div
$(“#消息”).val(“”);
loadLog();
}
});
}
$('#form')。提交(函数(){
//提交表格
sendData();
返回false;
});
loadLog();
设定间隔(负荷记录,5000);
这段代码工作正常,直到我将jquerymobile主题js添加到文件的head部分,然后我要么得到一个空白页面,要么加载页面,但chat text div是空的,永远不会加载
在添加jquerymobile节之前,文件的工作副本如下所示:
断开的一个位于以下url:
所有包含的内容都位于这些页面位置的正确相对url中,因此如果您想查看脚本和css标记中加载的内容,可以通过url加载它们
请帮我解决这个问题。第一个测试可能是使用“mobileinit”事件。 “mobileinit”替换jQuery的“document.ready”(在您的示例中为空),并在JQM完全加载后激发,请参阅 试着这样包装你的代码,也许会有帮助
$( document ).on( "mobileinit", function() {
function loadLog(){
$.ajax({
url: "chattextd.php?room=<?php echo $roomid; ?>&sid=<?php echo $sid; ?>",
cache: false,
success: function(html){
(document.getElementById("chatbox")).innerHTML = "";
$("#chatbox").html(html); //Insert chat log into the #chatbox div
}
});
}
function sendData(){
$.post ('chathandlerb.php',{message: form.message.value,roomid: form.roomid.value,cmode: form.cmode.value,sid: form.sid.value});
$.ajax({
url: "chattextd.php?room=<?php echo $roomid; ?>&sid=<?php echo $sid; ?>",
cache: false,
success: function(html){
(document.getElementById("chatbox")).innerHTML = "";
$("#chatbox").html(html); //Insert chat log into the #chatbox div
$("#message").val("");
loadLog();
}
});
}
$('#form').submit(function() {
// submit the form
sendData();
return false;
});
loadLog();
setInterval (loadLog, 5000);
});
$(document).on(“mobileinit”,function()){
函数loadLog(){
$.ajax({
url:“chattextd.php?room=&sid=”,
cache:false,
成功:函数(html){
(document.getElementById(“chatbox”).innerHTML=“”;
$(“#chatbox”).html(html);//将聊天日志插入#chatbox div
}
});
}
函数sendData(){
$.post('chathandlerb.php',{message:form.message.value,roomid:form.roomid.value,cmode:form.cmode.value,sid:form.sid.value});
$.ajax({
url:“chattextd.php?room=&sid=”,
cache:false,
成功:函数(html){
(document.getElementById(“chatbox”).innerHTML=“”;
$(“#chatbox”).html(html);//将聊天日志插入#chatbox div
$(“#消息”).val(“”);
loadLog();
}
});
}
$('#form')。提交(函数(){
//提交表格
sendData();
返回false;
});
loadLog();
设定间隔(负荷记录,5000);
});
查看自己的代码总是很好,我想,我只是在该页面的php标题中发现了一个潜在的SQL注入,并修复了它。如果我只能访问聊天记录表的话,那将是一个小问题。不幸的是,这不起作用,我也尝试过摆弄它,但我得到了完全相同的结果。就好像jquery主题和jquery.min.js不能共存一样