从php获取html内容作为json的问题

发布于 2024-11-01 05:43:34 字数 4211 浏览 2 评论 0原文

我在搜索了一些东西后尝试了。它不工作。请帮助我

----------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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

靑春怀旧 2024-11-08 05:43:34

首先通过 JSONLint 运行 PHP 文件的输出,看看它是否是有效的 JSON。

Run the output of the PHP file through JSONLint first to see if it's valid JSON.

纸伞微斜 2024-11-08 05:43:34

在黑暗中拍摄:

您需要发送正确的 MIME 类型

header('Content-Type: application/json; charset=utf8');
echo $reqfunc_to_box;

Shot in the dark:

You need to send the correct MIME Type.

header('Content-Type: application/json; charset=utf8');
echo $reqfunc_to_box;
雪花飘飘的天空 2024-11-08 05:43:34

尝试更改:

$(current_action_reqfunc_to_id).load(data['reqfunc_box_html']);

$(current_action_reqfunc_to_id).html(data['reqfunc_box_html']);

Try changing:

$(current_action_reqfunc_to_id).load(data['reqfunc_box_html']);

To

$(current_action_reqfunc_to_id).html(data['reqfunc_box_html']);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文