dongsuo9982 2013-07-03 13:34
浏览 99

如何将值从html文件传递到php文件

I am new to jQuery,Ajax and all, I don't know to pass a value of html file to php file.

For Eg: my html file as

<html>
<script>
     $(document).ready(function(){  
     $(".teachers_but").click(function(){
//alert('teacher');
var id=0;
alert(id);  
      });
    $(".students_but").click(function(){
//alert('student');
    var id=1;   
      });
     }); 
       </script>
     <div class="teachers_but"><a href="join.php">TEACHER SIGNUP</a></div>
      <div class="students_but" style="text-align: center; margin-top: 8px;"><a                        href="signup.php">STUDENT SIGNUP</a></div>
    </html>

How to pass id value in html file to php file and set cookie for that value.

  • 写回答

1条回答 默认 最新

  • dsf487787 2013-07-03 13:47
    关注

    I think this question comes up somewhat often, and the comment answers are correct; but you also have to understand what's happening during the request. I'll try to keep it kind of simple.

    On the SERVER, PHP processes all the PHP tags of your file, and turns it into a file consisting of pure HTML, Javascript, and CSS. The server sends this to the CLIENT (the person with the web browser hundreds of miles away). That client doesn't even know what PHP is, and the server will actually then shut down that little PHP environment it had created; all variables are destroyed, and it waits for the next client request to process a page again.

    Using a specially-coded in-page request, often referred to as AJAX (Asynchronous Javascript and XML, the XML part being a misnomer) you can start new requests against the PHP server to save information, request new information, etc, without loading a new webpage.

    HOWEVER, your specific question has a unique aspect to it; you want to set a cookie. Although you normally only see cookies when working in PHP, the cookies are actually stored on the client's computer, and are sent to the server on each request. Javascript is able to access them on its own, and some libraries can help with that.

    I haven't followed this tutorial myself, but a quick Bing search found this, which might help you: http://www.electrictoolbox.com/jquery-cookies/

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)