从php获取html内容作为json的问题
我在搜索了一些东西后尝试了。它不工作。请帮助我
----------jquery 函数 ----------------------------
function show_reqfunc_to_box(this_id){
var enc_item_id = this_id;
enc_item_id = enc_item_id.split("--")[1];
reqfunc_to_item_id_hidden = '#reqfunc_to_item_id_hidden--'+enc_item_id;
item_id = $(reqfunc_to_item_id_hidden).val();
var current_action_reqfunc_to_id = '#current_action_reqfunc_to_id--'+enc_item_id;
if(($(current_action_reqfunc_to_id).css('display'))=='none'){
$.getJSON('./ajax_funcs.php?func=reqfunc_to_box',{item_id_reqfunc_to:item_id,enc_item_id:enc_item_id},function(data){
$('.current_action_reqfunc_to_and_chain').hide();
$(current_action_reqfunc_to_id).center_box();
$(current_action_reqfunc_to_id).load(data['reqfunc_box_html']);
//$(current_action_reqfunc_to_id).center_box();
$(current_action_reqfunc_to_id).show();
});
}
}
-------- -php代码获取HTML内容---------
function reqfunc_to_box($item_id,$encod_item_id){
$usr_n_item_details_qry = 'some query to get data'
$usr_n_item_details_res = mysql_query($usr_n_item_details_qry);
$usr_n_item_details_row = mysql_fetch_array($usr_n_item_details_res);
$item = $usr_n_item_details_row['item'];
$cur_usr_name = $usr_n_item_details_row['usr_name'];
$cur_usr_img_name = $usr_n_item_details_row['usr_img'];
//echo ($cur_usr_img_name);die(0);
$action_to_do = 'reqfunc';
$pick_friends_for_reqfunc = ajax_fcs::chain_and_reqfunc_fn($action_to_do,$encod_item_id,$usr_n_item_details_row,$item_type);
$cur_usr_img = ajax_fcs::get_usr_img($usr_n_item_details_row['usr_id'],$cur_usr_img_name,$cur_usr_name);
$chain_and_reqfunc_res_id = 'chain_and_reqfunc_res_id--'.$encod_item_id.'--'.$action_to_do;
$chain_and_reqfunc_selected_res_id = 'chain_and_reqfunc_selected_res_id--'.$encod_item_id.'--'.$action_to_do;
$reqfunc_to_box = '';
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table style='width:100%;background-color:#43BFC7;border-collapse:collapse'><tr><td style='width:94%'><label class='pick_interest_heading_lbl'>reqfunc to specific friends</label></td><td><label class='reqfunc_to_close_lbl'>X</label></td></tr></table>";
// $reqfunc_to_box.= "<div class='pick_interest_heading_div'><label class='pick_interest_heading_lbl'>reqfunc to specific friends</label></div>";
// $reqfunc_to_box.= "<div class='pick_interest_close_div'><label class='reqfunc_to_close_lbl'>x</label></div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div style='border:1px solid #CDC2C2;width:100%'>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table style=''><tr><td style='width:11%'>$cur_usr_img</td><td><div class='' id='yah'><label class='item_text_pick_interest_lbl'>$item</label></div></td></tr></table>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table class='pick_friends_for_reqfunc_tbl_cls'><tr><td><label class='all_labels_in_colour'>reqfunc Friends</label></td><td class='pick_friends_for_reqfunc_td_cls' >$pick_friends_for_reqfunc</td></tr></table>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div style='float:left;width:70%;' id=\"$chain_and_reqfunc_res_id\"></div><div style='float:left;'><input type='button' value='reqfunc' class='reqfunc_box_btn' style='display:none;cursor:pointer'></div>";
$reqfunc_to_box.= "<div style='float:left;width:70%;' id=\"$chain_and_reqfunc_selected_res_id\"></div>";
$reqfunc_to_box = json_encode(array('reqfunc_box_html'=>$reqfunc_to_box));
echo $reqfunc_to_box;
}
i tried after searching several stuffs. its not working. pls help me
----------jquery function ----------------------------
function show_reqfunc_to_box(this_id){
var enc_item_id = this_id;
enc_item_id = enc_item_id.split("--")[1];
reqfunc_to_item_id_hidden = '#reqfunc_to_item_id_hidden--'+enc_item_id;
item_id = $(reqfunc_to_item_id_hidden).val();
var current_action_reqfunc_to_id = '#current_action_reqfunc_to_id--'+enc_item_id;
if(($(current_action_reqfunc_to_id).css('display'))=='none'){
$.getJSON('./ajax_funcs.php?func=reqfunc_to_box',{item_id_reqfunc_to:item_id,enc_item_id:enc_item_id},function(data){
$('.current_action_reqfunc_to_and_chain').hide();
$(current_action_reqfunc_to_id).center_box();
$(current_action_reqfunc_to_id).load(data['reqfunc_box_html']);
//$(current_action_reqfunc_to_id).center_box();
$(current_action_reqfunc_to_id).show();
});
}
}
--------php code to get HTML content---------
function reqfunc_to_box($item_id,$encod_item_id){
$usr_n_item_details_qry = 'some query to get data'
$usr_n_item_details_res = mysql_query($usr_n_item_details_qry);
$usr_n_item_details_row = mysql_fetch_array($usr_n_item_details_res);
$item = $usr_n_item_details_row['item'];
$cur_usr_name = $usr_n_item_details_row['usr_name'];
$cur_usr_img_name = $usr_n_item_details_row['usr_img'];
//echo ($cur_usr_img_name);die(0);
$action_to_do = 'reqfunc';
$pick_friends_for_reqfunc = ajax_fcs::chain_and_reqfunc_fn($action_to_do,$encod_item_id,$usr_n_item_details_row,$item_type);
$cur_usr_img = ajax_fcs::get_usr_img($usr_n_item_details_row['usr_id'],$cur_usr_img_name,$cur_usr_name);
$chain_and_reqfunc_res_id = 'chain_and_reqfunc_res_id--'.$encod_item_id.'--'.$action_to_do;
$chain_and_reqfunc_selected_res_id = 'chain_and_reqfunc_selected_res_id--'.$encod_item_id.'--'.$action_to_do;
$reqfunc_to_box = '';
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table style='width:100%;background-color:#43BFC7;border-collapse:collapse'><tr><td style='width:94%'><label class='pick_interest_heading_lbl'>reqfunc to specific friends</label></td><td><label class='reqfunc_to_close_lbl'>X</label></td></tr></table>";
// $reqfunc_to_box.= "<div class='pick_interest_heading_div'><label class='pick_interest_heading_lbl'>reqfunc to specific friends</label></div>";
// $reqfunc_to_box.= "<div class='pick_interest_close_div'><label class='reqfunc_to_close_lbl'>x</label></div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div style='border:1px solid #CDC2C2;width:100%'>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table style=''><tr><td style='width:11%'>$cur_usr_img</td><td><div class='' id='yah'><label class='item_text_pick_interest_lbl'>$item</label></div></td></tr></table>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div>";
$reqfunc_to_box.= "<table class='pick_friends_for_reqfunc_tbl_cls'><tr><td><label class='all_labels_in_colour'>reqfunc Friends</label></td><td class='pick_friends_for_reqfunc_td_cls' >$pick_friends_for_reqfunc</td></tr></table>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "</div>";
$reqfunc_to_box.= "<div style='float:left;width:70%;' id=\"$chain_and_reqfunc_res_id\"></div><div style='float:left;'><input type='button' value='reqfunc' class='reqfunc_box_btn' style='display:none;cursor:pointer'></div>";
$reqfunc_to_box.= "<div style='float:left;width:70%;' id=\"$chain_and_reqfunc_selected_res_id\"></div>";
$reqfunc_to_box = json_encode(array('reqfunc_box_html'=>$reqfunc_to_box));
echo $reqfunc_to_box;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先通过 JSONLint 运行 PHP 文件的输出,看看它是否是有效的 JSON。
Run the output of the PHP file through JSONLint first to see if it's valid JSON.
在黑暗中拍摄:
您需要发送正确的 MIME 类型。
Shot in the dark:
You need to send the correct MIME Type.
尝试更改:
至
Try changing:
To