我有一个条形码枪,当我扫描条形码时,它会运行下面的功能,但当我扫描5-6个条形码时,它会给出重复的数据
另外,我需要异步是真的,否则它会很慢,有没有办法解决这个问题,这样我就不会有重复的数据了?
function getUnReadBox() {
$("#unReadBoxList").children().remove('li') ;
$.ajax({
dataType: "json",
url: xxxx.php ,
success: saveUnRead ,
error: function ( xhr , b , c ) {
$("#reportMsg").html ( "error" ) ; },
async: true });
}
function saveUnRead ( json ) {
var i ;
var new_item ;
var msg ;
for ( i in json ) {
new_item = '<li>' + json[i].PACKAGE_ID + "</li>" ;
$("#unReadBoxList").append ( new_item ) ;
scShipping.unReadBox ++ ;
$("#unReadBox").html ( msg ) ;
}
$("#unReadBoxList").listview('refresh') ;
}编辑
我添加了
$("#unReadBoxList").children().remove('li') ;
var d = new Date();
var num = d.getTime();
var mySQL = scShipping.jsonUrl+'scTripUnRead.php?T='+scShipping.tripId+"&O="+scShipping.whichOp+"?date="+num ;
$.ajax({
dataType: "json",
url: mySQL ,
success: saveUnRead ,
error: function ( xhr , b , c ) {
$("#reportMsg").html ( "error" ) ; },
async: true });
}但是我仍然得到重复的数据
发布于 2014-03-28 11:54:23
我和你以前也有同样的问题。我得到的解决方案是在调用php程序时将数字时间戳作为参数传递,或者将日期作为参数传递。例如,如下所示:
xxxx.php?date=2014-03-28 20:54:52:03
它对我有效,我希望它对你也有效...
发布于 2014-03-28 12:17:04
这可能是因为web浏览器缓存了您请求的数据,通过避免这种情况,您可以尝试以下方法:
POST而不是GET。在method.type的参数中,将POST赋值给$.ajax。在url method.false赋给cache一个附加的参数和值,可以是随机数或时间戳,如xxxx.php?t=Math.random()或xxxx.php?t=new Date()。这将确保您的请求urls不同,并且不会缓存响应数据。发布于 2014-03-28 12:32:34
就像@user3311636建议的那样,您可以在Ajax调用代码中添加一个额外的参数。这样服务器或您的浏览器就不会缓存响应。
试着这样做(它是@user3311636的答案,为了清楚起见,我只是包含了整个函数)
$.ajax({
dataType: "json",
url: "xxxx.php?date=2014-03-28 20:54:52:03" ,
success: saveUnRead ,
error: function ( xhr , b , c ) {
$("#reportMsg").html ( "error" ) ; },
async: true }); https://stackoverflow.com/questions/22703571
复制相似问题