简体   繁体   中英

Ajax call html page contain JQuery

I load an html page containing a jquery function with Ajax.

Page A calls Page B with ajax. In Page B, some HTML is generated and contains some jquery functions. But I think he tries to run the jquery on page B. I get errors $ is undefined and my jquery source are in Page A.

Can I prevent the execution of javascript on Page B?

Here is my call from Page A:

var options = {
            dataType: 'html',
            beforeSubmit: function () {

                $('#' + s_Target_Response).animate({
                    opacity: 0
                });

            },
            success: function (response) {

                $("#loading").offset({ top: 1, left: 1 });

                $('#loading').hide();

                Init();

                $('#' + s_Target_Response).html(response);
                $('#' + s_Target_Response).animate({
                    opacity: 1
                });
            }
        };

         // pass options to ajaxForm 
        $('#' + s_Target_Form).ajaxForm(options);

        $('#' + s_Target_Form).submit();

If you want to prevent the execution of the script on Page B; and since you dont have jQuery defined on page B; Wrap your scripts in

if( typeof jQuery !== 'undefined' ){
  //page B scripts
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM