doutang3760 2017-02-02 09:59
浏览 134
已采纳

jQuery AJAX和PHP没有获取数据值

I am trying to fetch the values of the data variable passed with jQuery AJAX to a php page. How to solve it?

Below is the HTML page code:

<input id="name" placeholder="Enter your name." />
<button id="submit">Submit</button>
<div id="message"></div>

On the button click this jQuery AJAX calls a php page:

 $.ajax({
     type: "POST",
     url: "jquery-ajax-hello.php",
     contentType: "application/json; charset=utf-8",
     data: '{"name":"' + $("#name").val() + '"}',
     success: function (result, status, xhr) {
         $("#message").html(result);
     },
     error: function (xhr, status, error) {
         $("#message").html("Result: " + status + " " + error + " " + xhr.status + " " + xhr.statusText)
     }
 });

The PHP Page code is:

<?php
$name = $_POST['name'];
echo "Hello ".$name.", How are you ?"; 
?>

In the php page I am not able to fetch the data varaible 'name' value?

Please help?

  • 写回答

4条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 关于#大数据#的问题:请问有人能系统得总结一下什么数据分析师,数据架构师还有开发师的具体职业要求和就业前景嘛d(ŐдŐ๑)
      • ¥15 win10账户不见了怎么找回
      • ¥15 如何显示得分大于0.5的检测框
      • ¥15 微信小游戏使用云开发的CDN配置
      • ¥15 Matlab的SAW模态耦合模型的仿真程序
      • ¥20 求个C# SSL socket的客户端和 服务端代码
      • ¥15 大家调试TI C2000系列DSP用什么上位机?
      • ¥20 Eltable 如何实现鼠标拖拽范围多选
      • ¥15 产品需要了解什么代码技术才能更好站在开发角度思考问题?
      • ¥15 统计数据能提前统计吗