0

I'm using the below jquery function to send data from a form and get the reply back. Below is the Jquery function I use to get the result :

$(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 :

<?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. How can I call this.

1 Answer 1

3

Don't cast objects to strings:

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

Debug objects as objects:

console.log("Error: ", t);
Sign up to request clarification or add additional context in comments.

2 Comments

Although this won't fix the fact there's an error, at least we can see what the error is, then.
@Cerbrus - That's it. It's an AJAX error handler: no matter how good your code is, HTTP connections can always fail, any time. There's no way to "solve" the error in general terms.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.