【问题标题】:load php files as templates into div upon page load在页面加载时将 php 文件作为模板加载到 div 中
【发布时间】:2013-06-21 12:39:11
【问题描述】:

我正在尝试创建一个单页应用程序。加载索引页面后,我想将两个 php 模板加载到各自的 div 中。其中一个模板是登录表单,另一个是注册表单。从我一直在阅读的内容来看 - 似乎我需要使用 ajax“get”请求来执行此操作(因为我无法将两个文件传递给 jquery 的 load() 函数)。这是我所拥有的:

应用程序.js

$(document).ready(function() {
    $.ajax({
        type: "GET",
        url: "templates/loginform.php",
        data: somedata,
        success: function(somedata){
            $('#login').append(somedata);
        }
    });

    $.ajax({
        type: "GET",
        url: "templates/regform.php",
        data: somedata,
        success: function(somedata){
            $('#register').append(somedata);
        }
    });
});

我得到的只是一个空白页。

【问题讨论】:

    标签: jquery ajax templates get single-page-application


    【解决方案1】:

    解决方案:

    $.get('templates/regform.php', function(data) {  
        $('#register').append(data);
    });
    

    【讨论】:

    • 感谢您指出错误...但是页面仍然是空白的。
    • 您使用哪种浏览器?查看控制台,您将看到所有错误!
    • 我使用 firebug...没有更多错误...它只是显示帖子并获取索引加载时发生的调用。
    • 变量“somedata”中有什么?尝试写data: {},而不是data: somedata,
    • 我假设 get 请求中的所有数据都存储在要操作的变量中...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多