wordpress - How to run AJAX request with no conflict? -


i have function in functions.php file makes json request. how calling function:

define('is_ajax_request', isset($_server['http_x_requested_with']) && strtolower($_server['http_x_requested_with']) == 'xmlhttprequest'); if (is_ajax_request){ loadmore(); } 

above code works fine, problem conflicts other ajax request, example, see error message saying cannot execute loadmore() when try upload image.

i tried following none worked.

if (is_ajax_request && is_page()){ loadmore(); } 

+

if (is_page()){ if (is_ajax_request){ loadmore();    } } 

+

if (is_ajax_request){ if (is_page()) loadmore();  } } 

and here loadmore function

function loadmore(){    header('content-type: application/json');   echo json_encode (array ('rsp'=>'ok',          'payload'=> drawpostlist($_get['tribe'], $_get['offset']),          'lionly'=> true,          'tribe'=> $_get['tribe'],          'offset'=> $_get['offset']+20));   exit; } 

i wanna execute loadmore() function when viewing page. how can ?

<?php add_action( 'wp_head', 'my_action_javascript' );  function my_action_javascript() {      is_page() { // load script on pages  ?>         <script type="text/javascript" >         function loadmore() {              var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';             jquery.ajax({                     type: "post",                     url: ajaxurl,                     data: { action : 'loadmore_trigger', var1 : 'test', var2 : 'one more' }             })         }.done(function( response ) {             alert(response);          }         </script>         <?php     } }   add_action('wp_ajax_nopriv_loadmore_trigger', 'loadmore_trigger'); add_action('wp_ajax_loadmore_trigger', 'loadmore_trigger');  function loadmore_trigger(){  echo "<pre>"; print_r($_post); exit;  } ?>  <input type="submit" onclick="loadmore(); return false;"> // make ajax call on click of submit button 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -