没有表单方法的POST(PHP) [英] POST without Form Method (PHP)

查看:114
本文介绍了没有表单方法的POST(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以使用POST方法将内容从一个页面传递到另一个页面,而不使用表单。



像在get中一样,只需附加一个与任何你想发送的东西。你可以为帖子做点什么吗?

我还读了另外一个说使用会话的线程。但会话在用户计算机上保存为cookie,并且cookie不安全。



那么还有其他方法可以做到吗?就像在第一页描述一些东西,然后将它传递到第二页。



如果有人能解释我POST方法是如何工作的,它是如何传递数据的?

解决方案

你应该使用jQuery来做到这一点。你可以使用 ajax()函数。请访问下面的链接并阅读功能列表的完整说明以帮助您。但是这里仍然是一个示例代码---

HTML代码::::::::

 < HMTL> 
< head>
< script type =http://code.jquery.com/jquery-1.5.1.min.js>< / script>
< / head>
< body>
< div class =my-fake-form>
< input id =posting-value-1type =text/>
< / div>
< / body>
< / html>

AJAX CODE ::::::::

  function fake_form_submit()
{

var post = $('input#posting-value-1')。val();

$ .ajax({
'url':'your-php-file.php',
'type':'POST',
'dataType' :'json',
'data':{post:post},
'success':function(data)
{
if(data.finish)
{
$(div.my-fake-form)。attr(innerHTML,Form Submited!);
}
else
{
$(div.my-fake-form)。attr(innerHTML,Form Not Submited!);
}
},
beforeSend:function()
{
$(document).ready(function(){
$(div.my-fake-form)。attr(innerHTML,Loading ....);



$ b $ error $:
$($) div.my-fake-form)。attr(innerHTML,ERROR OCCURRED!);
});
}
});

$ b $(document).ready(function(){

$('a#submit-form-link')。click ){
e.preventDefault();
fake_form_submit();
});

PHP CODE ::::::

 <?php 

$ post = $ _POST ['post'];

//做一些值!

//在Succes上返回json编码数组!

echo json_encode(array(finish=> true));

?>

LINKS ::::::



* AJAX DESCRIPTION LINK



* AJAX功能链接



* AJAX学习链接


Is there any way to pass stuff from one page to another using the POST method without using forms.

Like in get you can just append a ? with whatever you want to send. Can you do something for post.

I also read one other thread which said to use sessions. But sessions are saved on the users computer as cookies, and cookies are unsecure.

So is there any other way to do it? Like describe something in the first page and then pass it to the second page.

Also it would be good if anyone could explain me how does the POST method work? And how does it pass data?

解决方案

You should use jQuery to this. you can use ajax() function in it. Visit the link below and read the full description of it with the functions list to help you out. But still here is a sample code for you ---

HTML CODE ::::::::

<hmtl>
    <head>
        <script type="http://code.jquery.com/jquery-1.5.1.min.js"></script>
    </head>
    <body>
        <div class="my-fake-form">
            <input id="posting-value-1" type="text" />
            <a id="submit-form-link" href="#submit">Submit this Div!</a>
        </div>
    </body>
</html>

AJAX CODE ::::::::

function fake_form_submit ()
{

    var post = $('input#posting-value-1').val();

    $.ajax({
    'url': 'your-php-file.php',
    'type': 'POST',
    'dataType': 'json', 
    'data': {post: post},
    'success': function(data)
     {
         if(data.finish)
         {
            $("div.my-fake-form").attr("innerHTML","Form Submited!");
         }
         else
         {
            $("div.my-fake-form").attr("innerHTML","Form Not Submited!");   
         }
     },
     beforeSend: function()
       {
            $(document).ready(function () {
                $("div.my-fake-form").attr("innerHTML","Loading....");
            });
       },
        'error': function(data)
        {
          $(document).ready(function () {
            $("div.my-fake-form").attr("innerHTML","ERROR OCCURRED!");
          });
        }
      });
}

$(document).ready(function () {

    $('a#submit-form-link').click(function (e) {
       e.preventDefault();
       fake_form_submit();
});

PHP CODE ::::::

<?php

    $post = $_POST['post'];

    //Do Something with the value!

    //On Succes return json encode array!

      echo json_encode(array("finish" => true));

?>

LINKS ::::::

*AJAX DESCRIPTION LINK

*AJAX FUNCTIONS LINK

*AJAX LEARNING LINK

这篇关于没有表单方法的POST(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆