Php 通过jquery发送数据时出现问题
我通过jquery发送数据。我的等效代码是Php 通过jquery发送数据时出现问题,php,jquery,ajax,Php,Jquery,Ajax,我通过jquery发送数据。我的等效代码是 $('#pcpmnum').blur(function(){ //alert("HIiiiiii"); var pcpmnum = $("#pcpmnum").val(); if(pcpmnum === "" | pcpmnum === null) { alert("Please Enter Mobile Number"); } else { alert(pcpmnum); $.
$('#pcpmnum').blur(function(){
//alert("HIiiiiii");
var pcpmnum = $("#pcpmnum").val();
if(pcpmnum === "" | pcpmnum === null)
{
alert("Please Enter Mobile Number");
}
else
{
alert(pcpmnum);
$.post("searchpcp.php", {cntctnumber: "+pcpmnum+"}, function(){
alert("Success");
}
}
});
在我的php文件中,我只是简单地使用了
echo "HIIII";
这个$.post函数等同于Ajax函数吗?只需这样做即可
{cntctnumber: pcpmnum, second:"second variable" }
在php文件中,可以得到如下值
$contact = $_POST["cntctnumber"]; // you will get the value of pcpmnum here
$sec = $_POST["second"]; // you will get "second variable" here
在成功回调中,您案例中的参数data
包含服务器响应,例如,在php文件中,您正在echoing
...
echo"howdy";
在客户端,数据
将保存此响应
$.post("searchpcp.php", {cntctnumber: pcpmnum, second:"second variable" }, function(data){
alert(data);//howdy
});
这里有一些有用的链接
如果我需要发送两个变量?第二,这是否等同于发送Ajax请求?如果我使用
函数(数据)
我将编辑两个变量的答案,是$。post
在后端使用ajax调用,这只是$的简写。ajax
我想返回一个数据数组。并根据返回的数据填充相应的文本字段。假设我输入的是id=firstname
,第二个是'id=middlename'。我正在我的PHP文件中启动querey。我将如何返回这些数据。我已经发布了一些链接,希望它们能帮助$。post是$.ajax的快捷方式,因此您不必填写太多选项。$。post
是带有特定预设的$.ajax
的缩写()。从代码中,它应该正确地调用searchpcp.php
,但是为什么要将pcpmnum
作为字符串传递,而不是传递其值(没有引号和+es)?