python小菜 2016-09-20 10:00 采纳率: 0%
浏览 36

结合使用jQuery mobile和ajax

I am trying to print a jQuery mobile thing using ajax but it doesn't encode the result as jQuery mobile is supposed to do.
This is a simplified version of the part of the javascript code that is supposed to do so:

   <script type="text/javascript">
       function changePage(task) {
           var objText = "";
           $.ajax({
               type: "POST",
               url: "DataFetch.aspx/FetchData",
               data: '{id: ' + <%=Session["loggedID"] %> + ', task: ' + task + ' }',
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: function (response) {
                   var obj = JSON.parse(response.d);
                   if (task == 2)
                   {
                       objText += "<div data-role='collapsible'><h3>click me</h3><p>text</p></div>";
                   }
                   document.getElementById('content' + task).innerHTML = objText;
               }
           });

       }

</script>

How can I make it work? (when I write it explicitly in the html or outside the ajax functions it works but I need it to work with json)

  • 写回答

1条回答 默认 最新

  • weixin_33744141 2016-09-20 13:01
    关注

    Try changing

    document.getElementById('content' + task).innerHTML = objText;
    

    to

    $('#content' + task).HTML(objText).enhanceWithin();
    

    The enhanceWithin() call tells jQM to enhace the new content you added via AJAX: http://api.jquerymobile.com/enhanceWithin/

    评论

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python