weixin_33698043 2019-01-23 17:37 采纳率: 0%
浏览 23

更改预加载的内容[AJAX]

My files: signup.php, form.php, success.php, failure.php.

In signup.php there's an area <div id="myarea"></div>. Inside of this block I load the form.php by default via <?php include ("form.php"); ?>.

Now I want to show the success.php or failure.php whether the signup was successfull or not.

My Question: How can I replace the content/loaded file in myarea? (Until now I did not wrote the file the data of the form is sent to.)

EDIT: I'm new to php and so on

  • 写回答

1条回答 默认 最新

  • weixin_33698823 2019-01-23 17:51
    关注

    This is not using ES2017, but it is a simple example and will give you the general idea.

    I assume you are using ajax to verify the login, so something like below.

    When you come back from the ajax (that is, inside the ajax .done() or .success or whatever-you-use function, you can either use $.load() to load the new content and $('#myarea').html() to replace the content of the #myarea div, or even something as simple as $('#someHiddenDiv').show() to reveal a previously hidden div.

    Here is a simplistic example:

    var my_id = $('#loginid').val();
    var my_pw = $('#loginpw').val();
    $.ajax({
        type: 'post',
         url: 'ajax/login.php',
        data: 'id=' +my_id+ '&pw=' +my_pw,
    }).done(function(recd){
        if (recd==1) {
            var newhtml = $.load('success.php');
            $('#myarea').html(newhtml);
            //-OR-
            //$('#myhiddendiv').show();
        }else{
            $('#loginid').val('');
            $('#loginpw').val('');
            alert('Please try logging in again');
        }
    });
    

    Now that you see a very basic example, here is how we do it these days:

    How to do AJAX in 2018

    Understanding the Fetch API

    Async/Await in 2017

    评论

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格