Javascript 从PHP Codeigniter到AJAX获取价值
我在php中有一个变量,我想在ajax中检查这个变量值是否为单词“RMA” 这是我在ajax中的功能Javascript 从PHP Codeigniter到AJAX获取价值,javascript,php,jquery,ajax,codeigniter,Javascript,Php,Jquery,Ajax,Codeigniter,我在php中有一个变量,我想在ajax中检查这个变量值是否为单词“RMA” 这是我在ajax中的功能 if ($.cookie("spare-items-loaded") == 1) { if ($.cookie("spare-items")) { cookie_items = $.cookie("spare-items").split(","); if (cookie_items
if ($.cookie("spare-items-loaded") == 1) {
if ($.cookie("spare-items")) {
cookie_items = $.cookie("spare-items").split(",");
if (cookie_items.length > 0) {
var request = $.ajax({
url: "<?=site_url('spares/get_json_selected');?>",
type: "POST",
data: {
ids: cookie_items.join(","),
},
dataType: "json",
success: function(data) {
var template = null;
var source = null;
var result = null;
result = jQuery.parseJSON(JSON.stringify(data));
source = $("#spare-loop-list").html();
template = Handlebars.compile(source);
$("#equipment-list").append(template(result));
cookie_items = jQuery.unique(cookie_items);
$("#total-spares").html(cookie_items.length);
}
});
}
} else {
$("#equipment-container").hide();
$("#total-spares").html( 0 );
}
}
if($.cookie(“加载的备用项”)==1){
如果($.cookie(“备用项”)){
cookie_items=$.cookie(“备用项”).split(“,”);
如果(cookie_items.length>0){
var请求=$.ajax({
url:“”,
类型:“POST”,
数据:{
ID:cookie\u items.join(“,”),
},
数据类型:“json”,
成功:函数(数据){
var模板=null;
var source=null;
var结果=null;
result=jQuery.parseJSON(JSON.stringify(data));
source=$(“#备用循环列表”).html();
template=handlebar.compile(源代码);
$(“#设备清单”).append(模板(结果));
cookie\u items=jQuery.unique(cookie\u items);
$(“#总备件”).html(cookie#items.length);
}
});
}
}否则{
$(“#设备容器”).hide();
$(“#总备件”).html(0);
}
}
首先,我们决定将POST
数据发送到哪个URL
$url = ''; //Initialize $url as global variable
if($var === "RMA"){
$url = "site_url('equip_request/get_json_selected')";
}else{
$url = "site_url('spares/get_json_selected')";
}
然后将$url解析为ajax请求
url: "<?=$url;?>",
url:“”,
顺便说一句,当使用
时,我会感到厌倦。如果$url在javascript中,你需要回显它。是的,我会这样做。那么我可以在哪里在ajax中添加我的php变量呢?这是我的变量$erf\u header->purpose=“RMA”很抱歉,我无法理解您在这段代码中的意思,我只是ajax中的新手
$url = ''; //Initialize $url as global variable
if($var === "RMA"){
$url = "site_url('equip_request/get_json_selected')";
}else{
$url = "site_url('spares/get_json_selected')";
}
url: "<?=$url;?>",