dsf5989 2015-11-05 10:44
浏览 59

从html表单发送数据到PHP JSON方式

I'm trying to send POST data using JavaScript. I have data in HTML form :

<form name="messageact" action="">
    <input name="name" type="text" id="username" size="15" />
    <input name="massage" type="text" id="usermsg" size="63" />
    <input name="submitmsg" type="submit"  id="submitmsg" value="Send" />
</form>

after press submit key i want to send name and massage to my PHP file ! a wrote this for my JavaScript in html : post.php , with post method

$(document).ready(function(){
    //If user submits the form
    $("#submitmsg").click(function(){   
        var clientmsg = $("#usermsg").val();
        $.post("post.php", {text: clientmsg});              
        $("#usermsg").attr("value", "");
        return false;
    });

and for my php i wrote this :

if(isset($_SESSION['name'])){
    $text = $_POST['text'];
    ....
    ....

but in PHP i couldn't receive anything ! please help me to solve this problem ! and how can i change it to JSON way ?

  • 写回答

4条回答 默认 最新

  • douhe8981 2015-11-05 10:47
    关注

    Why do you need to store name in the $_SESSION? If you have used $_SESSION by mistake change this

    if(isset($_SESSION['name'])){
    $text = $_POST['text'];
    ....
    ....
    

    to this and it should work

    if(isset($_POST['text'])){
        $text = $_POST['text'];
        ....
        ....
    

    The $_POST and $_SESSION are 2 different variables. You might wanna take a look at this and this

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型