-1

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;

}
  • 4
    So, you're requesting for JSON, but you're sending yourself HTML.. and what's not working? Clarify it, and try to google what JSON is. You can't mix apples and oranges and expect bananas. – Michael J.V. Apr 13 '11 at 15:14
  • http://stackoverflow.com/questions/5646062/loading-html-content-as-a-json . i did this on seeing the last post in this link. nothing happens on the execution of the jquery function – rajprashanth r Apr 13 '11 at 15:19
  • It seems you are saying JSON when you mean AJAX? – James Khoury Apr 14 '11 at 05:30
  • You are only listening to the complete callback from the ajax call. Try listening to the error callback and logging that error on your console. It might point you out towards where specifically is your code breaking. My guess would be its breaking trying parse JSON when in fact its receiving a HTML block. – Victor D. Oct 01 '14 at 21:06

3 Answers3

0

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

Mike Thomsen
  • 33,992
  • 10
  • 50
  • 76
0

Shot in the dark:

You need to send the correct MIME Type.

header('Content-Type: application/json; charset=utf8');
echo $reqfunc_to_box;
zzzzBov
  • 157,699
  • 47
  • 307
  • 349
0

Try changing:

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

To

$(current_action_reqfunc_to_id).html(data['reqfunc_box_html']);
Rocket Hazmat
  • 204,503
  • 39
  • 283
  • 323