开发者

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

开发者 https://www.devze.com 2023-03-05 11:46 出处:网络
I was using jquery for form submission it was working fine but when I included it in with other javascript libraries the .ready works but other events don\'t.

I was using jquery for form submission it was working fine but when I included it in with other javascript libraries the .ready works but other events don't.

$(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=$(th开发者_运维技巧is).attr('href');
        var formdata='';

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


You may take a look at the using jQuery with other libraries section of the documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消