php - 提交后获取内容
问题描述
我有这个脚本在提交后自动登录链接会改变,我想自动下载下一页我应该在最后一行之后添加什么是我的代码
<?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
谢谢
解决方案
由于缺乏细节,我将解释一个解决方案(我从你的问题中得到了什么)。
假设您在页面中有一个表单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']
密码。使用它们,操纵它们或任何你想要的,然后echo
在index.php
.
请注意:为了显示结果,您必须#results
在auto.php
. 如下所示:
<div id="results"></div>
现在所有数据index.php
都将在auto.php
不重定向的情况下显示。
推荐阅读
- python - Python 和 MySQL 中的数据透视表
- javascript - 点击不打开文件对话框
- javascript - 为什么 App.cs 在每个组件中运行,而不是在其他 css 组件中运行?
- python-3.x - 无法从 sklearn.preprocessing 导入“MinMaxScaler”
- javascript - 从 React 中的对象生成链接列表以创建动态 API 路由
- tensorflow - 如何对几乎所有黑色图像进行图像识别?
- pixi.js - pixijs webgl 中的screenslot 的screenslot 问题
- .net-core - .NET Core 3.1 Ubuntu 503 服务不可用/AH01114 无法连接到后端(端口 5000)
- python - 如何在不同类型的列表中找到最大和最小整数(python)
- flask - 在 Github 哪里可以找到稳定版 API(v1.0.0) 的 Airflow 路由信息?