Ajax发布工作但不是Android浏览器中的回调消息

时间:2013-11-16 05:33:45

标签: javascript php jquery ajax codeigniter

我在我的网站上使用ajax实现注册它在桌面上完美工作但在Android浏览器中引起问题问题是在我点击Android浏览器中的注册按钮后它将数据发布到数据库但不替换html消息。并且警告本机代码错误。

function postdata(){
    var chkfrm = checkdata();
    if(chkfrm == 0){
        var url = '<?php echo base_url();?>index.php/Signup/signin';    
        $.ajax({
           type: "POST",
           url: url,
           data: $("#formI").serialize(), // serializes the form's elements.
           beforeSend:function(){
               $("#signupdiv").html('<h1>Loadinng...........</h1>');
           },
           success:function(data)
           {
               $("#signupdiv").html(data);
           },
           error:function () {
                 alert(console.log);      
           }
        });
        e.preventDefault();
    }
    else {
        $("#msgjava").html('<p>We need a little bit information from you.Please fill it.</p>');
        return false;
    }

1 个答案:

答案 0 :(得分:2)

你不能在e.preventDefault();所在地,因为e没有传递给这个函数(因此未定义)。这将导致错误并停止JS执行。

在您发布的内容中,您还错过了postdata()函数末尾的右大括号。


您的提醒显示“本机代码”,因为这就是这行代码:

alert(console.log) 

会做的。 console.log是一个本机函数,因此警告本机函数不会做任何有用的事情。您需要使该警报更有用。要更详细地了解从ajax函数返回的错误,请将错误处理程序更改为以下内容:

    error: function(jqXHR, textStatus, errorThrown) {
        alert("status = " + textStatus + ", errorThrown = " + errorThrown);
    }

然后看看它说的是什么。