How to show data to the user using PHP?

I’m always trying to find new methods on development. So I looked into some websites and analyzed their ways of presentation.

  1. Returning part of the page using AJAX

    Normally I will use an array to return values, for example:

     //GET User details
    
     $user_id = $_POST['user_id'];
    
     $user_details = $this->get_user($user_id);
    
     if ($user_details['status'] == true) {
         exit(json_encode(array('status'=>true, 'data'=>$user_details['data'])));
     } else {
         exit(json_encode(array('status'=>false, 'reason'=>'SomeReasons....')));
     } 
    

But I see that some sites returning `HTML’. Is this preferable in any reason?

Also what is the best method to use: AJAX or an iframe?

I don’t necessarily agree entirely with Tom’s answer so I’m going to give my opinion.

Generally, you should avoid returning XHTML and instead return JSON, transforming the result into the DOM using JavaScript and your framework of choice.

There are some situations such as returning very large amounts of data where this isn’t just not practical, but you end up duplicating your presentation in both JavaScript and in the initial renderer. An example of this recently for me would be a reporting part of an application I was working on. I had the service endpoint configured to return XML data, for the web site I created an adaptor to transform the data with and XML stylesheet and return the XHTML. You could of course return XML to the browser and run the XSL client side.

In summary, generally return JSON however there are appropriate times, in my opinion, to return XHTML, and this is the reason as you say you see it online in places.

Use of an iframe is an “old fashioned” way to update part of the page without a full refresh. This is not the same effect as AJAX as most browsers will now days restrict programmatic access to the DOM of the iframe, so from that you can infer Ajax is the correct way to do it.

It’s always better to return JSON rather than HTML in your AJAX result. By returning HTML you’re letting your presentation layer leak into your data layer.

Generally speaking you should use AJAX rather than iFrames since its a neater solution and allows bookmarking (if you set it up). There are some use cases where iFrames are appropriate, for example when you need data from another site. For further reading have a look here and here.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật