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

Using jquery form submission was working fine until I added other JS libraries

本文关键字:添加 其他 JS 表单提交 jquery 工作 使用      更新时间:2023-09-26

我正在使用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');    
    });
}

你可以看看文档的 将 jQuery 与其他库一起使用的部分。