我的问题是,什么是更好的方式来做StackOverflow上的评论系统,我的意思是我从我的浏览器发送请求,每个人都会看到这个评论(或在其他浏览器中)没有刷新页面像一些聊天.
我的解决方案是使用setInterval,但我认为必须有另一种方式
$(document).ready(function() {
get();
$('#send').click(function() {
$.post('http://localhost/mvc.com/comment/post', {
n_id: parseInt(newsId),
user_id: $('#uid').val(),
text: $('#content').val(),
token: $('#token').val()
}, function (ret) {
if (ret.comm.err) {
$('.f').empty().prepend('<li id=e><h3 style="color: red">ERROR</h3></li>');
return false;
}
get();
});
setInterval(get,3000);
});
$('#content').keypress(function(e){
var key = e.which;
var cnt=$(this).val().length;
var max=100;
var tot=parseInt(max-cnt);
if(key >= 33 || key == 13 || key == 32) {
if (parseInt(tot) <= 0) {
e.preventDefault();
}
}
});
function get() {
$.post('http://localhost/mvc.com/comment', {get: parseInt(newsId)}, function (ret) {
$('.f').empty();
for …Run Code Online (Sandbox Code Playgroud) 你好我正在尝试开发Android应用程序来加载图像库中的图像.这是代码snipet.我无法显示图像.有人可以指出我哪里出错了吗?
*.html的
<ion-view title="Account">
<ion-content class="has-header padding">
<h1>Upload Image</h1>
<div class="account-picture">
<button ng-click="ShowPictures()">Select Picture</button>
<img src="ImageURI" id="smallimage">
<input type="text" ng-model="ImageURI" size="30"/>
</div>
</ion-content>
</ion-view>
Run Code Online (Sandbox Code Playgroud)
Controller.js
.controller('AccountCtrl', function($scope) {
$scope.ImageURI = 'Select Image';
function UploadPicture(imageURI) {
$scope.ImageURI = imageURI;
alert($scope.ImageURI );
}
$scope.ShowPictures = function() {
navigator.camera.getPicture(UploadPicture, function(message) {
alert('get picture failed');
}, {
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
};
});
Run Code Online (Sandbox Code Playgroud)
在这里ia ImageURI我正在接收afetr从图库中选择任何文件:content:// media/external/images/media/17.我盲目地为我的图像src硬编码了这个值.但我没有看到任何.这里有什么输入?
此外,ImageURI也没有绑定我的文本框.警报正确显示URI.
它看起来非常直接使用普通的phonegap应用程序.但我不喜欢离子框架.
我正在使用jVectorMaps.我有一个带有backgroundColor属性的地图对象:
map = new jvm.Map({
container: $('#map'),
map: "world_mill_en,
backgroundColor: bgcolor
Run Code Online (Sandbox Code Playgroud)
假设我声明了一个全局bgcolor变量.然后,我在某个时候更改该变量的值:
function changeBGcolor() {
bgcolor = "yellow";
}
Run Code Online (Sandbox Code Playgroud)
我的想法是,当我更改bgcolor变量的值时,jVectorMap背景颜色会发生变化.到目前为止,我无法做到这一点.
怎么做到呢?
我有一个应用程序,我正在连接到MySQL数据库.它在半夜失去连接,然后喷出null连接,JDBC在X秒内没有收到消息.
getConnection()在我做任何需要与SQL服务器通信的事情之前,我打电话.
这是我的getConnection()方法:
private Connection getConnection() {
try {
if (connection != null) {
if (connection.isClosed() || !connection.isValid(10000)) {
this.initializeRamsesConnection();
}
} else {
this.initializeRamsesConnection();
}
} catch (Exception e) {
debug("Connection failed: " + e);
}
return connection;
}
Run Code Online (Sandbox Code Playgroud)
在initializeRamsesConnection()方法中,我将密码等信息放入字符串中,然后以标准JDBC方式创建连接.
然后我称这个方法:
private Connection getConnectionFromConnectionString() {
Connection con = null;
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);//jdbc sorcery
//if there is no connection string
if (getConnectionString() == null) {
HMIDatabaseAdapter.debug("No connection string");
} …Run Code Online (Sandbox Code Playgroud) 在下列情况下我应该得到一个"警报",但我没有得到任何"警报".我正在尝试一个简单的例子jQuery.Contains().
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
var alpha = $.contains('body','p') {
alert(alpha);
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我尝试解密从Web服务收到的加密数据.
加密是使用完成的AES 128.
我使用以下代码来解密数据:
public static String decrypt(String strToDecrypt)
{
try
{
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding"); //AES/CBC/PKCS7Padding
SecretKeySpec secretKey = new SecretKeySpec(AppConstants.AESEncryptionKey.getBytes("UTF8"), "AES");
int blockSize = cipher.getBlockSize();
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(new byte[blockSize])); //new IvParameterSpec(new byte[16])
byte decBytes[] = cipher.doFinal(Base64.decode(strToDecrypt, 0));
// byte decBytes[] = cipher.doFinal(Base64.decodeBase64(strToDecrypt));
String decStr = new String(decBytes);
System.out.println("After decryption :" + decStr);
return decStr;
}
catch (Exception e)
{
System.out.println("Exception in decryption : " + e.getMessage());
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
在
cipher.doFinal()
我得到以下例外:
javax.crypto.badpaddingexception pad块损坏 …
我需要等到我的所有ajax函数完成后再继续执行exectution.
我的具体情况是我需要在提交之前翻译表单中的某些字段.我通过对外部站点的ajax调用来翻译它们.根据表单中的某些值,我需要做更多或更少的翻译.完成所有翻译后(如果有的话)我必须用ajax验证表单,如果有效,则提交.
这是我的方法:
首先,我有一个函数发送ajax调用并对收到的数据做一些事情:
function translate(...) {
$("#ajaxCounter").val(parseInt($("#ajaxCounter").val()) + 1);
$.ajax({
...
success:function(data) {
...
$("#ajacCounter").val(parseInt($("#ajaxCounter").val()) - 1);
}
});
Run Code Online (Sandbox Code Playgroud)
然后,当要提交表单时,我执行以下代码:
$("#form").submit(function() {
translatable_fields.each(function() {
translate(...);
});
while (parseInt($("#ajaxCounter").val()) > 0) { null; }
if (!(this).hasClass('ready')) {
$.ajax({
//validation
success: function(data) {
if (data['isValid']) {
$("#form").addClass('ready');
$("#form").submit();
}
}
});
}
return true;
});
Run Code Online (Sandbox Code Playgroud)
问题是while提交函数中的循环永远不会结束.
如果我在没有while循环的情况下执行代码,我可以看到ajaxCounter输入在翻译函数开始时增加,在结束时减少.
我有一个大型 HTML 表,其中正文的所有行都具有相同的结构。
在此表中,有可编辑的 TD(具有类“ editable”且包含可内容编辑的 div)和不可编辑的 TD(不具有类“ editable”并且不包含 div)。
现在我试图从与当前(最近的) TD 具有相同索引的下一行获取 TD。
下面的代码为我提供了当前 TD 在其行中的正确索引(并且仅查看可编辑的 TD)。
有人能告诉我如何获得下一行的等效 TD 吗?
我的 jQuery:
$(document).keydown(function(e) {
var current = $(e.target);
var editables = $(current).closest('tr').find('td.editable');
var count = editables.length;
alert( editables.index($(current).closest('td')) ); // for testing
// ...
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找类似以下内容的内容,而不是警报:
$(current).closest('tr').next('tr').find( /* the td with class editable AND the index matching the above */ );
Run Code Online (Sandbox Code Playgroud)
示例:
如果我当前处于连续第四个可编辑 TD 上,那么我将需要下一行中的第四个可编辑 TD。
如何显示菲律宾的本地日期和时间?
<? php
date_default_timezone_set('Asia/Manila');
echo "<span style='color:red;font-weight:bold;'>Date: </span>". date('F j, Y g:i:a ');
?>
Run Code Online (Sandbox Code Playgroud) 我有这个程序:
class DataRetrieve {
DataRetrieve() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook", "root", "1234");
Statement st = con.createStatement();
st.executeQuery("select * from contacts");
}
catch(Exception e) {
e.printStackTrace();
}
}
}
public class MainProgram {
public static void main(String[] args) {
DataRetrieve dr = new DataRetrieve();
//here i want to print that table rows into Console using this
System.out.println(); // How do you print here that table rows?
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释如何打印这个数据库信息System.out.println?