使用jquery表单提交工作正常,直到我添加其他JS库

时间:2011-05-13 13:47:13

标签: javascript jquery

我正在使用jquery进行表单提交它工作正常但是当我将其包含在其他javascript库中时.ready正常工作但其他事件却没有。

$(document).ready(jQueryCodeOfReady);
function  jQueryCodeOfReady()
{
   // arrays of target tags ..... w.r.t id
   var  hashtable  = new Array();
   hashtable['frm'] = 'result';
   hashtable['newaccount'] = 'content';

   /********************** AJAX related Section Started ******************************/
   function _(url  , data ,dataType,type  ,thetag)
   {
        /***Animation Code***/
        $(thetag).html("<span style=\"font-family:sans-serif;   color:#274d87;  background:url('loader.gif') no-repeat; padding-left:80px; width:164px; height:32px;  \">wait ... </span>");
        /***Animation Code ended***/

        $.ajax({
        type: type ,
        url: url ,
        data: data,
        dataType: dataType,
        success: function(data)
            {    
                // show content etc in this tag
                 $(thetag).html(data);    
            } // ajax call back function
        });

        return false;
    }
    /*************************************************** AJAX related Section endeed *****************************************************************/

    alert('sendf');

    /*************************************************** Events Section Started *****************************************************************/

     // Form submission using ajax ...  when event happens then specific code called
     $("form").submit(function (e)
     {
        // don't perform default html event behaviour
        e.preventDefault();

        // get form attribute and the taag in which the result should be shown
        var formid="#"+$(this).attr('id'); // identify the form
        var formaction=$(this).attr('action'); // the path where to move ahead after this event occurs
        var targettag="#"+hashtable[$(this).attr('id')]; // hashtable array declared upthere

        // get form data
        var formdata  = $(formid).serialize();

        // give serverCall
        _(formaction,formdata ,"text/html","POST",targettag );    
     });
     $("a.searchlink2").click(function (e){
        var path=$(this).attr('href');
        var formdata='';

        e.preventDefault();
     // give serverCall
        _(path,formdata ,"text/html","POST",'#result');    
    });
}

1 个答案:

答案 0 :(得分:2)

您可以查看文档的using jQuery with other libraries部分。