Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
charat(),substr()javascript函数不工作_Javascript_Jquery_Html - Fatal编程技术网

charat(),substr()javascript函数不工作

charat(),substr()javascript函数不工作,javascript,jquery,html,Javascript,Jquery,Html,我使用以下jquery脚本通过jquery提交表单。在jquery脚本中,我使用了charat()、substr()函数,但这些函数不起作用 以下是所需代码: $(document).ready(function() { $("#createuserbtn").click( function() { if( $("#userid").val() == "" || $("#first_name").val() == "" || $("#last_name").val()==""

我使用以下jquery脚本通过jquery提交表单。在jquery脚本中,我使用了charat()、substr()函数,但这些函数不起作用

以下是所需代码:

$(document).ready(function() {

$("#createuserbtn").click( function() {

    if( $("#userid").val() == "" || $("#first_name").val() == "" || $("#last_name").val()=="" 
        || $("#email").val()=="" || $("#user_group").val()==""  )
    {   
        $("#failurebox").html("<strong>All the fields are mandatory to enter !!</strong>");
        $("#failurebox").fadeIn(2000,function(){
            $("#failurebox").fadeOut(4000);
        });           
    }
    else
    {
        // collect data to array
        var data =   $("#newuserform :input").serializeArray();

        // send the data to the regprocess.php via post method              
        $.post( $("#newuserform").attr("action"),
                data,
                 function(info) {

                // clear the input fields
                clear();

                var str = info;
                var status = str.charAt(0);
                var message = str.substr(2);


                   // Show success message
                   if( status == '1')
                   {
                    $("#successbox").html('<b>' + message + '</b>');
                    $("#successbox").fadeIn(2000,function(){
                            $("#successbox").fadeOut(4000);
                        }); 
                   }
                   else
                   {
                    $("#failurebox").html('<b>' + message + '</b>');
                    $("#failurebox").fadeIn(2000,function(){
                            $("#failurebox").fadeOut(4000);
                        });
                   }


                 }); 

     }// end of else

        // abort the redirecting of the page 
        $("#newuserform").submit( function() {
             return false;
        }); // end of submit function

    });// end of click function 

}); // end of document ready function
$(文档).ready(函数(){
$(“#createuserbtn”)。单击(函数(){
如果($(“#userid”).val()==”|$(“#姓氏”).val()==”|$(“#姓氏”).val()
||$(“#电子邮件”).val()
{   
$(“#failurebox”).html(“所有字段都必须输入!!”;
$(“#failurebox”).fadeIn(2000年,函数(){
美元(“#故障盒”)。淡出(4000);
});           
}
其他的
{
//将数据收集到阵列
var data=$(“#newuserform:input”).serializeArray();
//通过post方法将数据发送到regprocess.php
$.post($(“#newuserform”).attr(“操作”),
数据
功能(信息){
//清除输入字段
清除();
var-str=info;
变量状态=str.charAt(0);
var message=str.substr(2);
//显示成功消息
如果(状态='1')
{
$(“#successbox”).html(“”+message+“”);
$(“#successbox”).fadeIn(2000,function(){
美元(“#successbox”)。淡出(4000);
}); 
}
其他的
{
$(“#failurebox”).html(“”+消息+“”);
$(“#failurebox”).fadeIn(2000年,函数(){
美元(“#故障盒”)。淡出(4000);
});
}
}); 
}//别有用心
//中止页面的重定向
$(“#newuserform”).submit(函数(){
返回false;
});//提交函数的结束
});//单击结束函数
}); // 文档结束准备功能
例如:如果我在php页面中回显“1 Successfull”作为错误消息。我的变量消息应该是Successfull,状态应该是1。因此,我应该弹出ID为failurebox、successbox的警报框。在这种情况下,它应该弹出successbox警报框,并显示消息Successfull。但它会弹出失败框,并显示消息“1 Successfull”


代码中有错误吗??我正在使用Mozilla firefox浏览器工作。这是浏览器的问题吗?我是jquery和javascript新手,请帮助我。用一个例子解释。

首先,您将
str
添加到您的框中,而不是
消息
其次,我认为您可以通过
console.log(str,status,message)来帮助自己调试它
var message=……..
之后,在诸如Firebug控制台之类的控制台中查看结果,并查看这些值显示的内容。@RobSchmuecker很抱歉混淆了它的实际消息不是str我已经再次编辑了它。控制台日志输出说了什么?或者,您可以在
if
之前执行
警报(状态)
的学童调试,这将显示
状态
包含的内容(毫无疑问不是1)@RobSchmuecker--console.log(str,status,message)不起作用!它没有在控制台中提供任何输出警报呢?!您必须在控制台中获得一些输出,否则脚本将无法执行?