【发布时间】:2018-06-20 08:25:43
【问题描述】:
我的 HTML 代码:
<form id="form" style="border: 2px solid white; padding: 20px;">
<div class="form-group">
<label for="username">Name</label>
<input type="text" class="form-control" id="username" placeholder="Name" name="name" required>
</div>
<div class="form-group">
<label for="username">Registration Number</label>
<input type="text" class="form-control" id="regno" placeholder="Registration Number" name="regno" required>
</div>
<div class="form-group">
<label for="username">Phone Number</label>
<input type="text" class="form-control" id="phone" placeholder="Phone Number" name="phoneno" required>
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="Email" name="email" required>
</div>
<button class="btn btn-primary sub_btn" id="submit" style="width: 100%; background-color: blue;">Subscribe</button>
</form>
我的 Javascript/Jquery 代码:
$('#form').on('submit', function(event){
event.preventDefault();
var phoneno = $('#phone').val();
if(phoneno.length > 12 || phoneno.length <10){
swal("Enter a valid phone no!!");
$('#form')[0].reset();
return false;
}
var regno = $('#regno').val();
var patt = /^([0-9]{2})([a-zA-Z]{3})([0-9]{3,4})$/;
if(!patt.test(regno))
{
swal("Enter a valid registration number");
$('#form')[0].reset();
return false;
}
var name = $('#username').val();
var email = $('#email').val();
if(name.length==0 || email.length==0){
swal("Enter all fields");
$('#form')[0].reset();
return false;
}
var data = {
'name' : $('#username').val(),
'email' : $('#email').val(),
'phoneno': $('#phone').val(),
'regno' : $('#regno').val()
};
console.log(data);
$.ajax({
type: "POST",
url: "https://reversecodingsubs.herokuapp.com/subs",
data: data,
cache: false,
dataType: "json",
encode: true,
beforeSend: function() {
$('.sub_btn').text('subscribing...');
}
}).done(function(data) {
swal("Great job!", "You are successfully registered!", "success")
$('.sub_btn').text('subscribe');
$('#form')[0].reset();
});
return true;
});
在所有其他 PC 浏览器和移动浏览器中一切正常,除了 android 中的 google chrome?究竟是什么导致了android chrome中的问题? 我试过没有缓存:假,但没有用, 我尝试将方法和操作属性放在表单上,然后在移动 chrome 中,它不起作用。 我在清除浏览器的缓存和 cookie 后尝试了所有这些方法,即使这样也没有用。
【问题讨论】:
-
具体是什么“没用”?
-
点击按钮后,没有任何反应,但在其他浏览器中,ajax 运行正常。
-
你能调试一下看看执行停止的地方吗?
-
@John Pavek,你的时间,我检查了控制台,它显示由于我的 API 请求使用 https,jquery CDN 被阻止,因为它是使用 HTTP 调用的。
-
如果您有时间,请添加详细说明您如何发现错误的答案,以便未来的读者可以看到路径
标签: javascript jquery ajax twitter-bootstrap