I have a form that sends data, the problem is in one in the str variable, there using & the data goes only in order, but the user can choose any order, let's say initially filterCategory, then the data will not be displayed. If or is used, then it will be impossible to make 2 or more requests.

<script> function f(fromDate=null, beforeDate=null, filterTyp=0, filterCateg=0, filterAccount=0, filterOrgan=0) { var fromDate = $("#fromDate").val(); var beforeDate = $("#beforeDate").val(); var filterTyp = $("#filterTyp").val(); var filterCateg = $("#filterCateg").val(); var filterAccount = $("#filterAccount").val(); var filterOrgan = $("#filterOrgan").val(); var str = "fromDate="+fromDate+"&beforeDate="+beforeDate+"&filterTyp="+filterTyp+"&filterCateg="+filterCateg+"&filterAccount="+filterAccount+"&filterOrgan="+filterOrgan; $.ajax({ url: "TransTable.php", type: "POST", data: str, success: function(data) { $("#TransTable").html(data); } }); } </script> 
 <input type="button" onclick="f(fromDate, beforeDate, filterTyp, filterCateg, filterAccount, filterOrgan)" name="filter" id="filterButtom" value="Фильтровать"> 

  • either you don’t have a problem, or you haven’t explained everything in a question. What exactly and where did you have a problem? from the fact that beforeDate and fromDate in the string are swapped, nothing will change on the server. They will all fall into the associative array and from there they will get by the corresponding keys (beforeDate, fromDate, etc.). Values ​​are bound to specific fields. How can they change? - Mikhail Rebrov
  • But what's the point of using parameters in a function if you don't use them? You override all the variables and get them from the form directly into the function and ignore the parameters so that you do not pass them there. - Mikhail Rebrov
  • in order for you to be able to help, please describe in more detail what your problem is, without any assumptions about what it may be. Write in more detail in the question what your form does, what happens after the form is submitted and what should happen. Whether the correct behavior of the form was observed at all, and if so, in what cases. If the error manifests itself in some specific conditions, then describe them too. - Mikhail Rebrov
  • one
    & in the query is not an element of Boolean algebra. OR cannot be in the request. - Mikhail Rebrov
  • and yes, we all look forward to the TransTable.php source code. The problem is surely in him - Mikhail Rebrov

1 answer 1

Something you have mixed. How do the fromDate parameter fromDate with the local variable fromDate and the global variable fromDate in the onclick="f(fromDate,... ?) onclick="f(fromDate,... ?

 function f() { var fromDate = $("#fromDate").val(); ... $.ajax({ url: "TransTable.php", type: "POST", data: { fromDate: fromDate, beforeDate: beforeDate, filterTyp: filterTyp, filterCateg: filterCateg, filterAccount: filterAccount, filterOrgan: filterOrgan }, ... <input type="button" onclick="f()" ... 
  • @ Igor doesn’t filter with me - Ruslan
  • Sorry, I forgot to put a comma - Ruslan
  • @ Ruslan What do you not "filter"? Are you talking about server php code? Where is he? - Igor
  • No, it still doesn’t work out. As it should, nothing comes out of me - Ruslan
  • @ Ruslan Because you are doing it wrong. - Igor