Home > Web Front-end > JS Tutorial > ajax gets the return parameters of the page and assigns values ​​to the control

ajax gets the return parameters of the page and assigns values ​​to the control

php中世界最好的语言
Release: 2018-04-03 14:04:18
Original
3236 people have browsed it

This time I will bring you ajax to get the return parameters of the page and assign values ​​to the control. What are the precautions for ajax to get the return parameters of the page and assign values ​​to the controls? Here is the actual combat Let’s take a look at the case.

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

I believe you have mastered the method after reading the case in this article, and there will be more exciting things Please pay attention to other related articles on php Chinese website!

Recommended reading:

How ajax handles the data type returned by the server

Ajax request WebService cross-domain implementation method ( Code attached)

The above is the detailed content of ajax gets the return parameters of the page and assigns 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