weixin_33704591 2015-08-31 10:20 采纳率: 0%
浏览 34

jQuery Ajax发送错误

I send a contact form with jquery ajax and the informations not successful sent. and the fields [object HTMLInputElement] error in email please help me

form code

<script type="text/javascript">
$(function() {
    $(".buttonmh").click(function() {
        var dataString = 'namet=' + namet + '&emailt=' + emailt + '&phonet=' + phonet + '&massaget=' + massaget;
        //alert (dataString);return false;
        $.ajax({
            type: "POST",
            url: "send.php",
            data: dataString,
            success: function() {
                $('#contact-formm').html("<div id='messagee'></div>");
                $('#messagee').html("<h2>The new message was sent!</h2>")
                    .append("")
                    .hide()
                    .fadeIn(1500, function() {
                        $('#messagee').append("");
                    });
            }
        });
        return false;
    });
});
</script>
<form action="" id="contact-form" class="main-contacts">
    <div id="messagee" class="error-sus" style="background:green; color:#fff;text-align:left;direction:ltr;"></div>
    <fieldset>
        <div class="col1">
            <div class="rowElem">
                <div class="bg">
                    <input type="text" name="namet" id="namet" value="<?php echo ContactName ;?>:" onblur="if(this.value=='') this.value='Name:'" onFocus="if(this.value =='Name:' ) this.value=''">
                </div>
                <label class="error" for="namet" id="name_error">
                    <?php echo RequiredFieldMessage ;?>
                </label>
                <label class="error" for="namet" id="name_error2">
                    <?php echo NotValidValueMessage ;?>
                </label>
                <input type="text" name="emailt" id="emailt" value="<?php echo ContactEmail ;?>:" onblur="if(this.value=='') this.value='E-mail:'" onFocus="if(this.value =='E-mail:' ) this.value=''">
                <input type="text" name="phonet" id="phonet" value="<?php echo ContactPhone ;?>:" onblur="if(this.value=='') this.value='Phone:'" onFocus="if(this.value =='Phone:' ) this.value=''">
                <textarea cols="1" rows="1" name="massaget" id="massaget" onBlur="if(this.value=='') this.value='Message:'" onFocus="if(this.value =='Message:' ) this.value=''">Message:</textarea>
                <button id="submit" class="buttonmh">
                    <?php echo SendMessage ;?>
                </button>
</form>

shut of email http://designak.ir/Untitled.jpg
send.php http://designak.ir/send.txt

  • 写回答

1条回答 默认 最新

  • 斗士狗 2015-08-31 11:09
    关注

    the fields [object HTMLInputElement] error

    That is what happens when you take an <input> and try to convert it into a string.

    You need to read its value and use that instead of the element itself.

    'namet=' + namet.value // etc
    

    You should also escape user input before slapping it into a URL.

    'namet=' + encodeURIComponent(namet.value) // etc
    
    评论

报告相同问题?