javascript - JS/jQuery passing $_POST information to PHP script -


it might simple thing, spent way time unsuccessfuly trying make work.

basically have following bootstrap buttons:

<div class="bs-example">     <div class="btn-group" data-toggle="buttons">         <label title="this display" class="btn btn-lg btn-info">         <input type="radio" name="todo" id="todo" value="enablessh"> enable ssh     </label>     <label class="btn btn-lg btn-info">         <input type="radio" name="todo" id="todo" value="migratedb"> migrate database     </label> </div> 

i have following button lower in page need use above selected value:

<button id="submit" class="btn btn-default" type="button">go!</button> 

when button clicked, triggers following jquery function:

$("#submit").click(function(){     var buttonvalue = $('#todo').val();     var phpfile = "submit.php";     var data =  {'action': buttonvalue};     $.post(phpfile, data, function (response) {         alert("data has been submitted successfully);     }); }); 

this should pass result of selected radio button php script:

<?php if (isset($_post['action'])) {     switch ($_post['action']) {         case 'enablessh':             alert("enablessh has been selected");             break;         case 'migratedb':             alert("migratedb has been selected");             break;     } } ?> 

the alert data has been submitted jquery function appears properly, alerts php script confirming has been passed not appearing.

sorry lengthy post. please help.

there no alert in php, it's serverside language has alert.

the solution return ajax call instead

<?php      if (isset($_post['action'])) {         switch ($_post['action']) {             case 'enablessh':                 echo "enablessh has been selected";                 break;             case 'migratedb':                 echo "migratedb has been selected";                 break;         }     }  ?> 

and you'd response

$.post(phpfile, data, function (response) {     alert("data has been submitted successfully");     alert(reponse); // alert here instead }); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -