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; } } });
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'); }
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!