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条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入