jQuery ajax在iOS中不起作用 [英] jQuery ajax not working in iOS

查看:1207
本文介绍了jQuery ajax在iOS中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一位工程师刚刚将他的iPad带给我,并显示了无法在我们的网站上使用的功能.该功能适用​​于Chrome和Firefox,但不适用于iPhone或iPad.这是3个选择框,当您单击第一个选择框的值时,它将运行ajax并填充第二个选择框.

One of our engineers just brought his iPad over to me and showed a feature not working on our site. This works in Chrome and Firefox, but it doesn't work on the iPhone or iPad. It's 3 select boxes that when you click the value in the first one, it runs ajax and populates the 2nd select box.

这是在iOS中不起作用的功能.

This is the functionality that doesn't work in iOS.

对于在哪里开始对此进行测试,我们有些困惑.谁能为从哪里开始调试提供一些建议,或者您能看到我们做错了什么吗?

We're a bit stumped on where to begin testing this. Can anyone provide some advice on where to begin debugging this or can you see anything we did wrong?

    $().ready(function () {
        $('.vehicle-search .make').bind('click', function (e) {
            var makeId = $(e.target).val();
            var container = $(e.target).parent('.vehicle-search');
            if (parseInt(makeId) > 0) {
                $.ajax({
                    url:  site.internal.url + '/lib/ajax/vehicle/make/getModelList.php',
                    type: 'post',
                    dataType: 'json',
                    success: function (r) {
                        if (r.length > 0) {
                            $('.vehicle-search > .model').html('');
                            $('.vehicle-search > .year').html('');

                            var html = '';
                            for (var i = 0; i < r.length; i++) {
                                html += "<option value='"+r[i].id+"'>"+r[i].name+"</option>";
                            }

                            $('.vehicle-search > .model').html(html);
                        } else {
                            alert('We did not find any models for this make');
                        }
                    },
                    error: function () {
                        alert('Unable to process your request, ajax file not found');
                        return false;
                    },
                    data: {
                        makeId: makeId
                        }
                });
            } else {
                $('.vehicle-search > .model').html('');
                $('.vehicle-search > .year').html('');
            }
        });
........

推荐答案

绑定到<select>change事件而不是click事件.

Bind to the change event of the <select> instead of the click event.

此外,您还应该为iPad启用开发者控制台,这样您就可以查看可能会或可能不会发生的任何JS错误.

Also, you should enable the Developer Console for the iPad so that you can see any JS errors that may or may not be occurring.

将来,将console.log语句放入事件处理程序中以进行健全性检查,以查看它们是否被调用,以及是否要确定它们在什么时候失败.

In the future, put in console.log statements in event handlers as a sanity check to see if they are getting called at all, and if they are to determine at what point they are failing.

这篇关于jQuery ajax在iOS中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆