没有表单方法的POST(PHP)

编程入门 行业动态 更新时间:2024-10-28 16:24:43
本文介绍了没有表单方法的POST(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

解决方案

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

HTML代码::::::::

< HMTL> < head> < script type =code.jquery/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="code.jquery/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)

本文发布于:2023-10-10 11:57:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   方法   PHP   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!