我正在尝试将使用jQuery AJAX传递的数据变量的值提取到php页面。 如何解决? p>
下面是HTML页面代码: p>
< input id =“name”placeholder =“输入你的 名称。” />
< button id =“submit”>提交< / button>
< div id =“message”>< / div>
code> pre>
< p>在按钮上单击此jQuery AJAX调用php页面: p>
$ .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(“结果:”+状态+“”+错误+“”+ xhr.status +“”+ xhr.statusText)
}
});
code> pre>
PHP页面代码是: p>
&lt;?php
$ name = $ _POST ['name'];
echo“你好 “。$ name。”,你好吗?“;
?&gt;
code> pre>
在php页面中,我无法获取数据变量'name'值? p>
请帮忙? p>
div>