Я хочу отправить данные с помощью GET или POST в другой php-файл на кнопку кнопки (NOT Submit) onClick (). Пожалуйста, помогите мне.
Позвольте мне дать вам простой HTML-метод post с использованием AJAX
test.php
<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script> $(function() { $("#Submit").click(function() { var value = jQuery("#txt").val(); var data=jQuery('#myform_new').serializeArray(); $.post('test1.php', { myform: data}); return false; }); }); </script> </head> <body> <form id="myform_new"> <input type="text" name="abc" value="abc" id="txt"/> <input type="text" name="abc1" value="abc1" id="txt1"/> <input type="button" name="Submit" id="Submit" value="Submit" /> </form> </body> </html>
Hello in there i have explain both ajax and get/post method, Please have look below link for get/post method for submit a form in php. http://www.tutorialspoint.com/php/php_get_post.htm This below code is used for submit form using ajax <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> </head> <body> <form id="formoid" action="studentFormInsert.php" title="" method="post"> <div> <label class="title">First Name</label> <input type="text" id="name" name="name" > </div> <div> <label class="title">Name</label> <input type="text" id="name2" name="name2" > </div> <div> <input type="submit" id="submitButton" name="submitButton" value="Submit"> </div> </form> <script type='text/javascript'> /* attach a submit handler to the form */ $("#formoid").submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); /* get some values from elements on the page: */ var $form = $( this ), url = $form.attr( 'action' ); /* Send the data using post */ var posting = $.post( url, { name: $('#name').val(), name2: $('#name2').val() } ); /* Alerts the results */ posting.done(function( data ) { alert('success'); }); }); </script> </body> </html>