简体   繁体   English

如何解决jquery.ajax()中的[object Object]错误

[英]How to solve [object Object] error in jquery.ajax()

I'm using the below jquery function to send data from a form and get the reply back. 我正在使用下面的jquery函数从表单发送数据并获得回复。 Below is the Jquery function I use to get the result : 以下是我用来获取结果的Jquery函数:

$(document).ready(function(){
    console.log( "ready!" );
    $("#button").click(function(){
        console.log("ready2");
        $.ajax({
            statusCode: {
                500: function() {
                    alert("error");
                }
            },
            url: './contact.php',
            type: "POST",
            data: {
                "name": $("#name").val(),
                "element_4_1": $("#element_4_1").val(),
                "element_4_2": $("#element_4_2").val(),
                "element_4_3": $("#element_4_3").val(),
                "email": $("#email").val(),
                "input4": $("#input4").val(),
            },
            error: function(t){
                console.log("Error: "+t);
            },
            success: function(data){
                $("#stage").text("Thank You");
            }
        });
    });
});  

Now The text form which is here sends the data : 现在,这里的文本形式发送数据:

<div class="col-lg-7 well">
    <h4 style="padding-top:8px;">Your email address will not be published. Required fields are marked <font color="red">*</font></h4>
    <label>Name<font color="red">*</font></label><br>
    <input class="form-control" style="height:35px;width:230px;border-radius:4px;" required type="text" name="name"/><br>
    <label>Phone<font color="red">*</font></label><br>
    <span>
        <input id="element_4_1" name="element_4_1" class="element text" size="3" maxlength="3" value=""  type="text"> -
    </span>
    <span>
        <input id="element_4_2" name="element_4_2" class="element text" size="4" maxlength="4" value="" type="text"> -
    </span>
    <span>
        <input id="element_4_3" name="element_4_3" class="element text" size="10" maxlength="10" value=""  type="text" required >
    </span>
    <br><br>
    <label>Email<font color="red">*</font></label><br>
    <input id="email" class="form-control" style="height:35px;width:230px;border-radius:4px;" required type="email" name="text"/><br>
    <label for="input4">Message</label>
    <textarea name="contact_message" class="form-control" rows="4" id="input4"></textarea>
    <p>&nbsp;</p>
    <button type="submit" style="margin-left:65px;"class="btn btn-large btn-info" id="button">Submit</button>   
</div>

And the contact.php which I call is like this : 我打电话的contact.php是这样的:

<?php
if( $_REQUEST[name] &&
    $_REQUEST[element_4_1] &&
    $_REQUEST[element_4_2] &&
    $_REQUEST[element_4_3] &&
    $_REQUEST[email] &&
    $_REQUEST[message]){
   echo " Thank You ";
}
?> 

I get this error when I call the function : jquery:-[object Object] error . 调用函数时出现此错误: jquery:-[object Object] error How can I call this. 我怎么称呼它。

Don't cast objects to strings: 不要将对象转换为字符串:

console.log("Error: "+t);

Debug objects as objects: 将对象调试为对象:

console.log("Error: ", t);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM