3

我有以下代码(工作正常),我想将其更改为 jQuery Form Plugin ajaxForm() :

$("#replysubmit").click(function() {
    var msg = $("#message").val();
    var attach = $("#attach").val();
    var id = $("input[name=hidden-ticketID]").val();
    if(msg == "") {
            alert("not null");
            $("#message").focus();
            return false;
        }
    $.ajax({
        type: 'POST',
        dataType: 'json',
        url: '/TicketSystem/support/view',
        async: false,
        data: {id: id, msg: msg, attach: attach},
        success: function(json) {
            $.post('/TicketSystem/support/ajaxmsg', { date: json.date, msg: json.msg }, 
            function(data){
                var newData = $('<div>').addClass('msgBlock').html(data).hide();
                newData.appendTo($('.msgWrapper')).slideDown('normal');
                goToByScroll('reply-form');
            });
            $("#message").val('');
            $("#attach").val('');
        }
    });
    return false;});

这是我写的 ajaxForm() :

$(document).ready(function() { 
var msg = $("#message").val();
var attach = $("#attach").val();
var id = $("input[name=hidden-ticketID]").val();
var options = { 
    //target:        '#output1',   // target element(s) to be updated with server response 
    beforeSubmit:  showRequest,  // pre-submit callback 
    success:       showResponse,  // post-submit callback 

    // other available options: 
    url: '/TicketSystem/support/view',
    type: 'POST',
    dataType: 'json',
    data: {id: id, msg: msg, attach: attach},
    //clearForm: true        // clear all form fields after successful submit 
    //resetForm: true        // reset the form after successful submit 

    // $.ajax options can be used here too, for example: 
    //timeout:   3000 
}; 

// bind form using 'ajaxForm' 
$('#user-reply-form').ajaxForm(options); }); 

来自 ajaxForm 的发布数据很奇怪......而且我的 php 代码无法从它接收任何东西,除了文件上传现在可以工作。

4

0 回答 0