problem in getting html content from php as json
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>";
$re开发者_Go百科qfunc_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;
}
Run the output of the PHP file through JSONLint first to see if it's valid JSON.
Shot in the dark:
You need to send the correct MIME Type.
header('Content-Type: application/json; charset=utf8');
echo $reqfunc_to_box;
Try changing:
$(current_action_reqfunc_to_id).load(data['reqfunc_box_html']);
To
$(current_action_reqfunc_to_id).html(data['reqfunc_box_html']);
精彩评论