我想每次用户点击一个按钮,在计数器中增加+1,并且每次用户点击时都会运行Ajax。
这仅适用于使用AJAX的测试,如果用户点击按钮,该功能将每次都有效。
我的HTML代码:
<html>
<head>
<meta charset="UTF-8">
<title>Demo</title>
<script src="jquery-3.1.1.js"></script>
<script src="JS.js"></script>
<!--script src="JS2.js"></script-->
</head>
<body>
<button id="1" onclick="dadosLog()">
Login
</body>
</html>
功能.js
:
var numberOrigin = 0 //
function dadosLog (){
numberOrigin++;
var obj = login("xxxLog", "xxxxxxxPassword", numberOrigin);
}
// Function 2 before function 1 its OK
function function2(otherParameter, numberOrigin){
console.log(xxxxxx);
$.ajax({
type: 'POST',
dataType: 'json',
contentType: "application/json",
url: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/request/create',
data: JSON.stringify({
"synchronize":false,
"sourceRequest":{
"numberOrigin":numberOrigin,
"description": "test"
}
},
}),
success:function(output) {
console.log(output);
alert(output.request.number)
},
error:function(output) {
return '0';
console.log(output);
}
});
}
答案 0 :(得分:0)
它的工作:
var counter = 10; // Enter the value you want to start the counter
function Function1(){
var obj = teste("xxxxxxx", "xxxxxxxxxxx", counter);
counter++;
}
var obj;
function teste (NameV, NameV2, counter){
counter +=1;
// function (...)
然后我将与银行和一个字段进行连接,它将检查计数器编号是否已经存在,如果不存在,则为+1