迁移到更高版本时,jquery提交无法正常工作

时间:2013-11-20 18:19:49

标签: javascript jquery ajax

您好我刚刚从jquery 1.10.2迁移到1.2.1以便使用tablesorter.js插件,但我的问题是我的jquery ajax帖子不再使用这个jquery版本了,我希望有人能弄明白问题或我缺少什么,这是我的代码:

js file

// variable to hold request
var request;
// bind to the submit event of our form
$("#postAtencion").submit(function(event){
    // abort any pending request
    if (request) {
        request.abort();
    }
    // setup some local variables
    var $form = $(this);
    // let's select and cache all the fields
    var $inputs = $form.find("input, select, button, textarea");
    // serialize the data in the form
    var serializedData = $form.serialize();

    // let's disable the inputs for the duration of the ajax request
    $inputs.prop("disabled", true);

    // fire off the request to /form.php
    request = $.ajax({
        url: "/admin/atencion",
        type: "post", 
        data: serializedData,
        success: function(response){ 
        // we have the response
        $('#tableSubView').html(response); 
        }
    });

    // callback handler that will be called on success
    request.done(function (response, textStatus, jqXHR){
        // log a message to the console
        console.log("Atencion Posted");
    });

    // callback handler that will be called on failure
    request.fail(function (jqXHR, textStatus, errorThrown){
        // log the error to the console
        console.error(
            "The following error occured: "+
            textStatus, errorThrown
        );
    });

    // callback handler that will be called regardless
    // if the request failed or succeeded
    request.always(function () {
        // reenable the inputs
        $inputs.prop("disabled", false);
    });

    // prevent default posting of form
    event.preventDefault();
});

Jsp文件

<div class="container">
        <h2>Consulta</h2>
        <form id="postAtencion" style="padding:19px;">
        <div>
         Number: <input type="text" name="msisdn" style="margin-left: 15px;" class="inputAtencion">
        </div> 
         Init Date: <input type="date" name="fechaInicio" class="inputAtencion">
         Final Date: <input type="date" name="fechaFin" class="inputAtencion">
        <input type="submit" value="Search" class="buscar"/> 
        </form>
    <div id="tableSubView"></div>

    </div>


    <script src="js/file.js"></script>
    <script src="js/atencion-post.js"></script>
    <script src="js/jquery-requiered.js"></script> 
    <script src="js/jquery.tablesorter.js"></script> 

0 个答案:

没有答案