doudaochu1699 2016-09-08 04:24
浏览 13
已采纳

无法使用AJAX向PHP字符串发送值

What is the actual deal in the Data part ?

<form id="form" name="form">
<input type="text" name="textname" id="textname">
<input type="button" name="submit" id="submit" onclick="post();">
</form>

function post()
{
  var textname = $('#textname').val();

    $.ajax
    ({
      url: 'post.php',
      data: {testurl:textname},
      type: "POST",
      success: function (data)
        {
          $('#test').html(data);
          console.log(data);
        }
      });
  }

And the post.php

<?php
      echo "test";

      $testurl = $_POST['textname'];

      echo var_dump($testurl); 
?>

Echo Test is working but Output for the var_dumb is NULL string(0) - Empty String

  • 写回答

2条回答 默认 最新

  • 「已注销」 2016-09-08 04:32
    关注

    Try to understand one simple thing, in ajax call the data parameter contains the

    key : value

    pair in it.

    Means if your data part is some thing like:

    data: {
       var1 : val1,
       var2 : val2,
    }
    

    than in your php function you can get these values using its keys i.e. var1, var2.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan