php – ajax problems on loading page


I wrote a code that when a user click on a button. contents will be displayed via ajax in wordpress.
I used wp_ajax_{action} and wp_ajax_nopriv_{action}. when I load the page ajax run without any content and after ajax end I refresh the page and then every thing is ok.
I don’t know why when I reload the page or open the page in another browser ajax starts without any triggers.
This is my code:

jQuery( document ).ready( function(){
   jQuery( ".pelak-order-type-item" ).click( function(){
        var data = {
            "action": "get_product_properties",
        var ajax_url = "'. admin_url( 'admin-ajax.php' ) .'"; ajax_url, data, function(response) {
            let generated_steps = jQuery( "#pelak_product_title" ).data( "step" );
            for ( var i=2; i<=generated_steps; i++ ){
                jQuery( "#step"+ i ).hide();
    } );
   } );
jQuery(document).ajaxStart(function() {
        jQuery( "#step-general" ).hide();
        jQuery( ".pelak-loader" ).show();
    }).ajaxSuccess(function() {
        jQuery( ".pelak-loader" ).hide();


Note: All of the above code in in php echo function and i copy the related part and pasted here.
Thank you for your attention to this matter.

hamzeh 1 year 2022-12-19T17:16:30-05:00 0 Answers 0 views 0

Leave an answer