如何将值e.regid
传递给tokenHandler
函数。我尝试从tokenHandler
调用onNotification
并且它正在工作,但是我想从提交按钮调用该函数,这样我也会得到一些其他值。
<!DOCTYPE HTML>
<html>
<head>
<title>Dr.Reminder</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/style.css" media="screen" type="text/css" />
</head>
<body>
<div class="wrap">
<div class="logo">
<img src="logo3.png">
</div>
<input type="text" placeholder="Email ID" id="username">
<div class="bar">
<i></i>
</div>
<input type="text" placeholder="Mobile Number" id="mobile">
<div class="bar">
<i></i>
</div>
<input type="text" placeholder="Patient ID" id="pid">
<div class="bar">
<i></i>
</div'<div class="bar">
<i></i>
</div>
<button onClick='tokenHandler(regid)'> Sign in</button>
</div>
<script type="text/javascript">
var pushNotification;
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch (e.event) {
case 'registered':
if (e.regid.length > 0) {
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
console.log("regID = " + e.regid);
}
break;
function tokenHandler(regid) {
var email = document.getElementById('username').value;
var mobile = document.getElementById('mobile').value;
var pid = document.getElementById('pid').value;
var xmlhttp;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.xxxxxxxxxxxxxx.in/temp.php?email=" + email + "&mobile=" + mobile + "&patientid" + pid + "&token=" + regid, true);
xmlhttp.send();
}
function successHandler(result) {
$("#app-status-ul").append('<li>success:' + result + '</li>');
}
function errorHandler(error) {
$("#app-status-ul").append('<li>error:' + error + '</li>');
}
document.addEventListener('deviceready', onDeviceReady, true);
</script>
<div id="home">
<div id="app-status-div">
<ul id="app-status-ul">
</ul>
</div>
</div>
</body>
</html>
这有效..!
$("#buttonId").click(function(){
tokenHandler(e.regid);
});
答案 0 :(得分:0)
认为您需要删除标记上的事件onclick。 然后在onNotification中创建事件处理程序,如下所示:
$(&#34;#buttonId&#34;)。on(&#39; click&#39;,function(){tokenHandler(e.regid);});