首页 > 解决方案 > 提交后获取内容

问题描述

我有这个脚本在提交后自动登录链接会改变,我想自动下载下一页我应该在最后一行之后添加什么是我的代码

<?php
$homepage = file_get_contents('localhost/test/login.php');
echo $homepage;
?>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js" ></script>
<script type="text/javascript">
  $(function(){
    $("input[name=email]").val("test@test.com");
    $("input[name=password]").val("test");
    $('#signin-form').submit();
  });
</script>

此脚本位于另一个名为auto.php. 所以当我运行它时它的工作但是在提交之后链接localhost/login.php将重定向到localhost/index.php所以我应该auto.php在提交后添加什么以获得我的内容ocalhost/index.php 谢谢

标签: phpjqueryajax

解决方案


由于缺乏细节,我将解释一个解决方案(我从你的问题中得到了什么)。

假设您在页面中有一个表单auto.php,它将向index.php. 您要求一种index.php无需重定向或类似方法即可检索数据/结果的方法。您可以通过以下方式做到这一点ajax

$('#signin-form').on('click', function(e){
    //e.preventDefault();
    var email= $("input[name=email]").val();
    var password = $("input[name=password]").val();
    $.ajax({
            url: 'index.php',
            type: 'POST',
            data: 'the_email='+ email +'the_pass'+ password ,
            success: function(respond){
                $('#results').html(respond);
            }
        });
});

index.php用于$_POST['the_email']电子邮件和$_POST['the_pass']密码。使用它们,操纵它们或任何你想要的,然后echoindex.php.

请注意:为了显示结果,您必须#resultsauto.php. 如下所示:

<div id="results"></div>

现在所有数据index.php都将在auto.php不重定向的情况下显示。


推荐阅读