[英]jquery redirect after post
I have 3 php files. 我有3个php文件。
file3.php generates a PDF using TCPDF, based on 2 variables that it receives in $_REQUEST, and displays the resulting PDF file3.php根据在$ _REQUEST中收到的2个变量,使用TCPDF生成PDF,并显示生成的PDF
So the jQuery code in file1.php where I call post is: 所以在file1.php中我称之为post的jQuery代码是:
$("#saveinv").click(function() { // button is clicked
var listview_array = new Array();
// here I populate the array with values then...
$.post("file2.php",
{json: JSON.stringify(listview_array)},
function(data){alert("success");
});
});
In file2.php there is nothing to see. 在file2.php中没有任何内容。 After much processing, I end up with 2 variables that help me call the file3.php
经过大量处理,我最终得到2个变量,这些变量可以帮助我调用file3.php
file3.php must be called with 2 params: var1 and var2 so something like: 必须使用2个参数调用file3.php :var1和var2,例如:
file3.php?var1=5&var2=77
But I have no idea where to place the call or what exact syntax to use. 但是我不知道在哪里放置调用或使用什么确切的语法。 I tried different solutions without success.
我尝试了不同的解决方案,但没有成功。 Maybe I was doing it wrong and you can help me.
也许我做错了,您可以帮助我。
I tried to : 我试过了 :
If I do window.location='file3.php?var1=5&var2=77' in file1.php then all works perfect, but I need those variables to be sent from file2.php. 如果我在file1.php中执行window.location ='file3.php?var1 = 5&var2 = 77' ,那么一切都完美,但是我需要从file2.php发送这些变量。 They are not constants.
它们不是常数。
What should I do, and where? 我该怎么办,在哪里?
Thank you 谢谢
Just put your result as JSON in file2.php: 只需将结果作为JSON放在file2.php中:
echo '({"var1":"1","va2":"2"})';
where you get it as data
inside your ajax callback function in file1.php, then use eval
在file1.php中的ajax回调函数中将其作为
data
获取的位置,然后使用eval
var args = eval(data);
window.location = 'file3.php?var1=' + args.var1 + '&var2=' + args.var2;
add at the end of file2.php the line : return 'file3.php?var1=5&var2=77';
在file2.php的末尾添加以下行:
return 'file3.php?var1=5&var2=77';
You cannot use return
, just use print
or echo
and it should work. 您不能使用
return
,而只能使用print
或echo
,它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.