EasyUI Forum
March 28, 2024, 03:52:40 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: QueryParams not working  (Read 11112 times)
stevemit
Newbie
*
Posts: 3


View Profile
« on: February 16, 2018, 07:39:30 AM »

I'm having trouble getting queryParams to work.  Help, please.

EasyUI v. 1.5.4.1
Firefox 58.0.2(64 bit)/Windows 7/Node JS (on localhost)

Node JS console:

GET /test.html 200 0.790 ms - 495
GET /easyui/themes/default/easyui.css 304 0.515 ms - -
GET /easyui/themes/icon.css 304 0.919 ms - -
GET /easyui/jquery.easyui.min.js 304 1.082 ms - -
GET /easyui/jquery.min.js 304 1.373 ms - -
GET /easyui/themes/default/images/loading.gif 304 1.128 ms - -
POST /consoles/consoles 200 1.908 ms - 28

(Note -- no query parameters on POST url.)

test.html:

<html>
  <head>
      <link rel="stylesheet" href="easyui/themes/default/easyui.css">
      <link rel="stylesheet" href="easyui/themes/icon.css">
    <script src='easyui/jquery.min.js'></script>
    <script src='easyui/jquery.easyui.min.js'></script>
 </head>
 <body>
     <table class="easyui-datagrid" data-options="url:'consoles/consoles',queryParams:{foo:7}">
       <thead>
           <tr>
             <th data-options="field:'name'">Name</th>
           </tr>
       </thead>
     </table>
 </body>
</html>
« Last Edit: February 16, 2018, 07:42:13 AM by stevemit » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 16, 2018, 06:06:39 PM »

Please refer to this example https://www.jeasyui.com/demo/test/test3.html. The 'foo' request parameter is posted to server successfully.
Logged
stevemit
Newbie
*
Posts: 3


View Profile
« Reply #2 on: February 17, 2018, 02:06:35 PM »

Thanks,

When using method GET, the parameters are included in the GET URL as query components.  When using method POST, the request body contains the url-encoded parameters.

  --Steve
Logged
geo77
Newbie
*
Posts: 3


View Profile Email
« Reply #3 on: March 17, 2018, 06:15:21 PM »

This seems to be an ongoing question with no clear and concise explanation. I'm facing this same problem going on 2 days trying different things and suggestions to no apparent solution.  Huh
All I need to do and apparently the OP as well, is to send a parameter from the datagrid call. I need this parameter in order to have one php file with multiple functions, instead of one php file for every datagrid load, update, delete...etc.
I really want to use easyui and want to implement it in my project, but if I can't get this to work, it is a deal breaker for me and would have to move on to something else.
My datagrid looks like this.
Code:
<table id="tt" title="Articulos" class="easyui-datagrid" style="width:700px;height:300px"
iconCls="icon-search"
toolbar="#toolbar, #tb" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true"
data-options="method:'post',url:'items.php',queryParams:{action:'items'}">
Have also tried this

Code:
<table id="tt" title="Articulos" class="easyui-datagrid" style="width:700px;height:300px"
url="items.php?action=items'
iconCls="icon-search"
toolbar="#toolbar, #tb" pagination="true"
rownumbers="true" fitColumns="true" singleSelect="true"
data-options="method:'post',url:'items.php',queryParams:{action:'items'}">

And a couple of other permutations.
In my php file items.php I am checking if the action parameter is being passed and check if its value is items, if so, then fire off a function within that php file that returns a json result which should be used to load the data grid.


Code:
<?php

include 
'conn.php'
(isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists
    
$action $_POST["action"];
    echo 
$action;
switch($action) { //Switch case for value of action
      
case "items"get_all_items(); break;
    }
  }

    function 
get_all_items(){
        
    
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;

$type_id = isset($_POST['type_id']) ? mysql_real_escape_string($_POST['type_id']) : '';
$brand_id = isset($_POST['brand_id']) ? mysql_real_escape_string($_POST['brand_id']) : '';
$color_id = isset($_POST['color_id']) ? mysql_real_escape_string($_POST['color_id']) : '';
$upc = isset($_POST['upc']) ? mysql_real_escape_string($_POST['upc']) : '';
$size_id = isset($_POST['size_id']) ? mysql_real_escape_string($_POST['size_id']) : '';
$gender_id = isset($_POST['gender_id']) ? mysql_real_escape_string($_POST['gender_id']) : '';
$material = isset($_POST['material']) ? mysql_real_escape_string($_POST['material']) : '';

$offset = ($page-1)*$rows;
$result = array();

$rs mysql_query("select count(*) from items");
$row mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs mysql_query("select * from items limit $offset,$rows");

$items = array();
while($row mysql_fetch_object($rs)){
array_push($items$row);
}
$result["rows"] = $items;

echo json_encode($result);
    }
    

?>



I really hope someone can let me know what I'm doing wrong here, because I can't figure out what I'm missing.
Sorry to the OP, didn't want to hijack your post, but seems like we are facing the same issue and didn't want to open a duplicate thread.

Thank you.
« Last Edit: March 17, 2018, 06:19:07 PM by geo77 » Logged
geo77
Newbie
*
Posts: 3


View Profile Email
« Reply #4 on: March 19, 2018, 05:46:51 PM »

Anybody??
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: March 19, 2018, 06:35:21 PM »

Please refer to this example https://www.jeasyui.com/demo/test/test3.html. The 'foo' and 'action' request parameters are posted to server successfully.

Here is the server code to receive the posted data.
Code:
<?php

$foo 
= isset($_POST['foo']) ? htmlspecialchars($_POST['foo']) : '';
$action = isset($_POST['action']) ? htmlspecialchars($_POST['action']) : '';

$queryParams = array('foo'=>$foo,'action'=>$action);

date_default_timezone_set('UTC');
$rows = array();
$rows[] = array(
'inv' => 'inv'.$foo,
'date' => date('Y-m-d',time()+24*3600),
'name' => 'Name' $foo,
'note' => 'queryParams:' json_encode($queryParams),
'amount' => $foo
);
echo 
json_encode($rows);
« Last Edit: March 19, 2018, 06:36:54 PM by stworthy » Logged
geo77
Newbie
*
Posts: 3


View Profile Email
« Reply #6 on: March 19, 2018, 07:06:16 PM »

Thank you, but if you look at my code, I did take the code from this example, however it is not working...
Does this mean that easyui is not able to handle data from a php function?
If I take the function and the parameters out of the equation everything works fine. It can not be possible that this platform expect us to use one php file for every grid action load, save, create,delete.. etc I do see that all the examples are formulated in this manner. Does this mean, that this is the only way for the programmer to use it?
If this is not the case and this framework is actually usable, please take a look at my code and point out what I'm doing wrong.

Thanks for your help!
« Last Edit: March 19, 2018, 07:46:08 PM by geo77 » Logged
Max Lamda
Newbie
*
Posts: 48


View Profile
« Reply #7 on: March 29, 2018, 02:20:14 AM »

If you

echo $action;


you destroy the output because this is then not a json-object anymore.



Logged
Max Lamda
Newbie
*
Posts: 48


View Profile
« Reply #8 on: March 29, 2018, 02:29:54 AM »

And easyui does just post the data and then gets json-data.

However you create that object on server-side it makes no difference for easyui.

Just remove your echo-line.

Else the answer to easyui looks like that:

items[{"nr":"ab","dummy":"dumm"},{"nr":"ab","dummy":"dumm"}]

That can't work. Try to JSON.parse() it, there will be no  result.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!