Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [jquery su wordpress] - onclick di un pulsante

    ciao! sto aggiungendo delle funzionalità ajax ad un plugin wordpress,
    ajax funziona solo usando determinate librerie wordpress e determinati script devo utilizzare questo script che vi posto

    lo script funziona al caricamento della pag mi stampa un numero dentro un div, io vorrei semplicemente che lo stampasse al click di un pulsante passandogli dei parametri, è jquery mi aiutate??

    codice:
    function my_action_javascript() {
    ?>
    <script type="text/javascript" >
    //$('#myButton').click(function(){
    
    jQuery(document).ready(function($) {
    
    	var data = {
    			action: 'my_special_action',
    			whatever: 7777
    		};
    	
    		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    		jQuery.post(ajaxurl, data, function(response) {
    			//alert('Got this from the server: ' + response);
    			document.getElementById("results_id").innerHTML =response;
    		});
    		
    	});
    });
    </script>
    <?php
    }
    
    function my_action_callback() {
    	
    	global $wpdb; // this is how you get access to the database
    
    	$whatever = $_POST['whatever'];
    
    	$whatever += 10;
    	
    	//echo "document.getElementById('results_id').innerHTML ='$whatever';";
    
           echo $whatever;
    
    	die();
    }
    io ho sostituito questo
    jQuery(document).ready(function($) {

    con
    jQuery(".inputsubmit").click(function(){

    questo è il pulsante:
    $out.="<button type='button' class='next right' class='inputsubmit' id='".$orderitem->idorder."' >Details</button>";
    poi c'è echo

    ma non funziona ugualmente, forse perchè i pulsanti sono tanti e generati dinamicamente per ogni record del db come dovrei fare per azionare l'onclick del pulsante?

    $out.="<button type='button' class='next right' class='inputsubmit' id='".$orderitem->idorder."' >Details</button>";

    vi ringrazio se mi aiutate

  2. #2
    L'importante è che ogni pulsante abbia un id diverso, che mi sembra nel tuo caso sia l'id dell'ordine, nel caso dovresti fare una cosa così:

    codice:
    jQuery(document).ready(function($) {
    	$('.inputsubmit').click(function(){
    		var data = {
    				action: 'my_special_action',
    				whatever: 7777
    			};
    		id = $(this).attr('id');
    
    		alert(id);
    		
    		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    		jQuery.post(ajaxurl, data, function(response) {
    			//alert('Got this from the server: ' + response);
    			document.getElementById("results_id").innerHTML =response;
    		});
    		
    	});
    });
    Ti ho messo un alert dell'id così vedi poi cosa farne.

  3. #3
    Grazie!!!funziona!Ti voglio bene! jquery mi veniva di salita!!!!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.