如何使用jquery将2个变量传递给php文档

时间:2022-09-05 15:08:32

Hello I have two text inputs which get their values from a datepicker. What I want to do is when user selects the two dates script pass these two values to a php document in which I make some checks and I return some html.

您好我有两个文本输入,从日期选择器获取它们的值。我想要做的是当用户选择两个日期时脚本将这两个值传递给php文档,我在其中进行一些检查并返回一些html。

Here is what I'm trying to do:

这是我正在尝试做的事情:

(#to and $from are 2 input texts)

(#to和$ from是2个输入文本)

$(document).ready(dateinput_change);
  function dateinput_change(){
    $('#to').change(check_availability);
    $('#from').change(check_availability);
  }
  function check_availability(){
    var to=$('#to').attr('value');
    var from=$('#from').attr('value');
    $.get("get_availability.php?to="+ to +"&from="+ from, show_availability);
  }
  function show_availability(available){
    $('#availability').html(available);
  }

1 个解决方案

#1


0  

I tend to use the ajax method. But you could write the following.

我倾向于使用ajax方法。但你可以写下面的内容。

 $.ajax({
          type: "GET",
          url: "get_availability.php",
          data: "to=" + to + "&from=" + from,
          success: show_availibility
     });

#1


0  

I tend to use the ajax method. But you could write the following.

我倾向于使用ajax方法。但你可以写下面的内容。

 $.ajax({
          type: "GET",
          url: "get_availability.php",
          data: "to=" + to + "&from=" + from,
          success: show_availibility
     });