douhuan1937 2016-07-05 07:21 采纳率: 0%
浏览 22
已采纳

PHP或jQuery的外观?

First, sorry for my English, you can correct me in that area too :)

I know that i can replace text in html with <?=$var?> for example. Also, i can do it through ajax. I use $.ajax to get data in JSON format, than inside jquery i'm changing appearance of my web app.

This is example of getting data, and inside this function i'm calling $.View function where apperance is changing.

$.Model = function(route, data){
    $.ajax({
        url: "php/books.php?"+route,
        type: "POST",
        data: {data: data}
    }).done(function(response){
        var resp = JSON.parse(response);
        $.View(route, resp, data);
    }).fail(function(msg){
        console.log('something is wrong');
    });
   });
};

Example of $.View function

$.View = function(route, response, data){
    if(route==='menuItem'){
        var studio='';
        $.each(response, function(index, value){
          studio += '<button id='+value['STUDIJI_ID']+' class="btn btn-primary studio_button">'+value['STUDIO']+'</button>';
        });
        $(studio).appendTo(".here");
    }
};

So, my question is, what is the best approach for such things? Embed PHP variable to html or do it through jQuery on described way? Or, something third?

Thank you for your time and help.

  • 写回答

1条回答 默认 最新

  • dortmundbvb0624 2016-07-05 07:46
    关注

    It depends on your requirements.

    If you know everything on page creation, insert the values with php. If you wnat to update only parts of your page after page is loaded, do it with ajax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?