[英]how to pass jquery variable one page to another?
index.php 的index.php
<script>
$(document).ready(function() {
$("#submit").click(function() {
var field = $("#field").val();
$("#popular_colleges" ).load( "xyz.php");
$("#popular_colleges").on( "click", ".pagination a", function (e){
e.preventDefault();
$("imagen").show();
var page = $(this).attr("data-page");
$("#popular_colleges").load("xyz.php",{"page":page}, function(){
$("imagen").hide();
});
});
});
</script>
xyz.php xyz.php
//another page code
Here I having two pages ie index.php and xyz.php now I want to post index.php page variable (var field) to xyz.php. 在这里,我有两个页面,即index.php和xyz.php,现在我想将index.php页面变量(变量字段)发布到xyz.php。 How can I do this ? 我怎样才能做到这一点 ? can anyone help me please ? 有人可以帮我吗?
Thank You 谢谢
You can use $.get(), or $.post(), or the more powerful and complex $.ajax(). 您可以使用$ .get()或$ .post(),或更强大和复杂的$ .ajax()。
For a simple value called page, get or post should be sufficient: 对于名为page的简单值,get或post应该足够了:
$.post('/path/to/other-page.php', {page: page}, function(data){
console.log(data); // what your other page returned
});
To post var field = $("#field").val();
要发布var field = $("#field").val();
from index.php
to xyz.php
you have to use the jquery ajax()
. 从index.php
到xyz.php
您必须使用jquery ajax()
。 To use this you have to include the jquery library in your page and its syntax is like: 要使用此功能,您必须在页面中包含jquery库,其语法类似于:
$.ajax({
url : 'xyz.php',
method : 'post',
data : {
field: field
// key: value pair
},
success: function(response){
// here response in the response you get from xyz.php
}
});
xyz.php: you can get the posted value like:
$field = $_POST['field'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.