繁体   English   中英

如何将值从文本框传递到没有表单的另一页

[英]How to pass value from textbox to another page without form

好的,我有这段代码,当用户单击提交但没有刷新页面且没有表单时,我想将此价格从价格发送到其他页面。在其他页面上,我将使用此输入进行sql查询并显示结果。

Price from:<input type="text" name="from" id="from" width="50px" />
Price to:<input type="text" name="to" id="to" width="50px" />
<input type="submit" id="submit" value="Search"/>

使用jquery

$('#submit').click(){
  event.preventDefault();// prevent form from submitting
   $.ajax({
     type: 'POST',
     url: 'targetpage.php', //your page here
     data: {price_from:$('#from').val() , price_to: $('#to').val()},
     success: function(response){
     }
  });
});  

嗨,您可以使用jQuery + Ajax实现此目的,请尝试

$('#submit').click(function(event) {

        var from = $('#from').val(); 
        var to   = $('#to').val();
        $.ajax({
                type: "POST",
                url: "page_name.php",
                data:"from="+from+"&to="+to,
                success: function (msg) {

                    //some action
                }
            });

    });

在您的php( page_name.php )文件中,您可以获得发布的值并可以执行必要的操作

$from = $_POST['from'];
$to   = $_POST['to'];
var _from = $('#from').val(); 
var _to   = $('#to').val();    
$.post('your_file.php',{from: _form, to: _to},function(data){
    //Do Something with returned data.
},'json');

'json'也可以是'html'具体取决于您要返回的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM