【问题标题】:Ajax not working in only android google-chromeAjax 仅在 android google-chrome 中不起作用
【发布时间】: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


【解决方案1】:

我在检查我的 android google chrome 浏览器的控制台后遇到了问题,它向我显示了错误说明,

如果在 https 中请求另一个脚本,则无法通过 HTTP 发出请求

(虽然不是类似的声明)。然后显示:

$ 未定义

然后我检查了在 HTTP 上请求 jquery CDN,当我将其更改为 https 时,一切正常。

【讨论】:

    猜你喜欢
    • 2019-04-12
    • 2013-06-25
    • 2014-12-24
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 1970-01-01
    • 2014-10-14
    • 2015-06-28
    相关资源
    最近更新 更多