php – ajax problems on loading page
Question
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:
<script>
jQuery( document ).ready( function(){
jQuery( ".pelak-order-type-item" ).click( function(){
var data = {
"action": "get_product_properties",
"whatever": this.id
};
var ajax_url = "'. admin_url( 'admin-ajax.php' ) .'";
jQuery.post( ajax_url, data, function(response) {
jQuery("#ajax-content").html(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();
});
</script>
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.
0
2 months
2022-12-19T17:16:30-05:00
2022-12-19T17:16:30-05:00 0 Answers
0 views
0
Leave an answer