我构建了一个页面,该页面在URL中为此页面生成了特定的ID (did)
,并且在其中包含了一个现成的jquery聊天脚本,允许两个人在其中聊天以达成交易。
问题在于无论页面的ID是什么,聊天条目在所有页面中都显示相同。
我如何编辑jquery代码以仅根据该页面的唯一ID出现聊天条目。
url:
http://localhost/bitcoin/deal/deal-sequence.php?deal_no=17&did=5b4d3983f104b
html:
<form id="submitForm" method="post" action="">
<input type="hidden" name="did_hidden" id="did_hidden" value="<?php echo htmlspecialchars($_GET['did']); ?>" />
<textarea cols="40" id="chatText" name="chatText" class="rounded"></textarea>
<!-- <input id="chatText" name="chatText" class="rounded" maxlength="255" /> -->
<input type="submit" class="blueButton" value="send" />
</form>
jquery代码:
$('#submitForm').submit(function(){
var text = $('#chatText').val();
if(text.length == 0){
return false;
}
if(working) return false;
working = true;
// Assigning a temporary ID to the chat:
var tempID = 't'+Math.round(Math.random()*1000000),
params = {
id : tempID,
author : chat.data.name,
gravatar : chat.data.gravatar,
text : text.replace(/</g,'<').replace(/>/g,'>')
};
// Using our addChatLine method to add the chat
// to the screen immediately, without waiting for
// the AJAX request to complete:
chat.addChatLine($.extend({},params));
// Using our tzPOST wrapper method to send the chat
// via a POST AJAX request:
$.tzPOST('submitChat',$(this).serialize(),function(r){
working = false;
$('#chatText').val('');
$('div.chat-'+tempID).remove();
params['id'] = r.insertID;
chat.addChatLine($.extend({},params));
});
return false;
});
php代码:
public static function submitChat($chatText){
if(!$_SESSION['user']){
throw new Exception('You are not logged in');
}
if(!$chatText){
throw new Exception('You haven\' entered a chat message.');
}
$chat = new ChatLine(array(
'author' => $_SESSION['user']['name'],
'gravatar' => $_SESSION['user']['gravatar'],
'text' => $chatText
));
// The save method returns a MySQLi object
$insertID = $chat->save()->insert_id;
return array(
'status' => 1,
'insertID' => $insertID
);
}