如何将数据发送到另一个PHP以使用post或get进行处理


how to send data onClick() to another php for processing using post or get?

我想使用 GET 或 POST 将数据发送到按钮(不是提交按钮(onClick(( 事件上的另一个 php 文件。请帮助我。

让我给你一个简单的 HTML with post 方法 使用 AJAX

测试.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>

Test1.php(ajax 调用文件(

<?php
echo "<pre>";print_r($_POST);
?>

让我给你一些ajax发布方法(1(

<script>
                    $(function() {
                        $("#Submit").click(function() {
                            var value = jQuery("#txt").val();
        					var data=jQuery('#myform_new').serializeArray();
                            $.post('test1.php', { myform: data});
                            return false;
                        });
                    });
                </script>

(二(

<script type="text/javascript"> $(function() { $("#Submit").click(function() 
		{ 
			var txt = jQuery("#txt").val(); 
			var txt1 = jQuery("#txt").val(); 
			$.post('test1.php', { txt: txt,txt1:txt1 }); return false; }); }); 
        </script>

(三(

 <script type="text/javascript"> $(function() { $("#Submit").click(function() { 
			var txt = jQuery("#txt").val(); 
			var txt1 = jQuery("#txt").val(); 
			$.post('test1.php', { data: "txt="+txt+"&txt1="+txt1}); return false; }); }); 
        </script>

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>