Home > Web Front-end > JS Tutorial > Ajax gets the return parameters of the php page and the method of assigning values ​​to the control

Ajax gets the return parameters of the php page and the method of assigning values ​​to the control

韦小宝
Release: 2017-12-30 18:53:22
Original
1978 people have browsed it

The following editor will bring you an article on how to obtain the return parameters of the php page through ajax and assign values ​​to the controls. The editor thinks it's pretty good, so now I'll share the source code of ajax with you, and also give you a reference. If you are interested in ajax, please follow the editor to have a look

js page

##

$.ajax({
type : "get",
url : "", //跳转页面
data :"m=content&c=favorite&a=del_favorite&shoucangId="+_id,//传递的参数
datatype : "html",
async:'false',
success : function(data) //返回值
{  if(data !=null)
   {
 var str= new Array(); //定义一数组
 str=data.split(","); //字符分割
 var title=str[0];
 var url=str[1];
 var type=str[2];
 var id=str[3];
 $("#title").val(title); // jQuery控件赋值
 $("#url").val(url);
 $("#shoucnag_id").val(id);
 if(type=='钢琴谱')
   $("input[name='radio'][value='钢琴谱']").attr("checked",true);
 else if(type=='钢琴曲')
   $("input[name='radio'][value='钢琴曲']").attr("checked",true);
   }
   else
   {
 alert('失败!');return false;
   }
 }
});
Copy after login

PHP page

$shoucangId=$_GET['shoucangId'];//获取传递的参数
$where="ID='$shoucangId'";
$signalInfo=array();
$signalInfo=$this->db->get_one($where,'*','',''); //此处借用PHPCMS二次开发的例子,select数据库中的一个数据集,存于数组$signalInfo中
if($signalInfo!=null)
{
 $str=$signalInfo['title'].",".$signalInfo['url'].",".$signalInfo['type'].",".$signalInfo['id'];//将要返回的数组用逗号拼接成字符串返回
 exit($str);
}
else
{
 exit('0');
}
Copy after login

The above is the entire content of the ajax method for obtaining the return parameters of the php page and the control assignment method brought by the editor. , I hope everyone will support the PHP Chinese website~

Related recommendations:

A brief analysis of the problem of json data transmitted from Ajax background success

Ajax example code for submitting Form form and file upload

Ajax implements partial refresh login interface with verification code

The above is the detailed content of Ajax gets the return parameters of the php page and the method of assigning values ​​to the control. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template