ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: nuno.nogueira on February 03, 2014, 06:10:55 pm
-
Hello again,
I'm looking at your "Batch editing" example.
Could you please share the PHP code for add, update, delete?
It seems you are using different files for the ajax calls.
Thanks in advance for your support!
-
PHP code is same as given in the PHP tab.
Rather there are few differences w.r.t URLs for PHP.
I've added comments in js code relevant to PHP
Enable the lines for PHP and comment out the lines specific to ASP.NET
-
That's easier to understand thanks.
I still can't figure out how the data for new rows data is being sent to PHP.
For example, when adding the last row of the attached image, I can see the #consola has logged:
[{"orcamento":"10","atual":"20","desvio":"","data":"2015-01-01","nome_conta":"BBB","nome_categoria":"abc","nome_entidade":"def"}]
which is the data I want to insert into the table.
But in PHP, nothing is being posted:
if( isset($_POST["addList"]))
{
$addList = json_decode($_POST["addList"], true);
var_dump ($addList);
echo "test";
exit();
}
This is outputing
NULLtest
How do I get the data in PHP so I can build a query and insert it into mySQL?
-
data for new rows is sent from line 38 to 50 in js
Did you remove / comment out all lines specific to ASP.NET e.g.
contentType: "application/json; charset=utf-8",//for ASP.NET
-
I did, here's the code for the ajax call:
//send to server
if (addList.length) {
$.ajax($.extend({}, ajaxObj, {
data: { "addList": JSON.stringify(addList) },
success: function (rows) {
$grid.pqGrid("commit", { type: 'add', rows: rows });
},
complete: function () {
$grid.pqGrid("hideLoading");
$grid.pqGrid("rollback", { type: 'add' });
$('#consola').text(JSON.stringify(addList));
}
}));
-
Could I have a look at your entire js code or a URL.
Your Ajax Call derives from ajaxObj, so more specifically, what's your code in ajaxObj?
-
You may see the whole code in attachment.
ajaxObj is defined before the ajax call.
-
WHat do you get with
if( isset($_POST["addList"]))
{
var_dump ($_POST["addList"]);
-
I get
NULL
I was expecting to get the changed data, as displayed on "#consola"
.
So the data isn't being sent to PHP and therefore, I'm not able to build the INSERT query to insert it into mySQL.
-
Let's try to narrow down the problem.
Try this
data: { "addList": '[{"UnitPrice":"10","Discontinued":false,"ProductName":"new ","QuantityPerUnit":"1","UnitsInStock":"1"}]' },
instead of
data: { "addList": JSON.stringify(addList) },
-
Same result: nothing is sent to the PHP script.
-
Could you send the whole Header log in Firefox (firebug) or chrome (developer tools).
like this:
Request URL:http://localhost:81/paramquery/products.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,es;q=0.6
Connection:keep-alive
Content-Length:182
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:PHPSESSID=5c7t0ltct2jto36ppe2stv6875
Host:localhost:81
Origin:http://localhost:81
Referer:http://localhost:81/paramquery/editing_batch.php
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
addList:[{"UnitPrice":"10","Discontinued":false,"ProductName":"new ","QuantityPerUnit":"1","UnitsInStock":"1"}]
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:249
Content-Type:text/html; charset=UTF-8
Date:Tue, 04 Feb 2014 12:01:23 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.4 (Win32) PHP/5.4.15
X-Powered-By:PHP/5.4.15
-
Here you go:
Request URL:http://www.portal-gestao.com/budget/incluir/json4.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:pt-PT,pt;q=0.8,en-US;q=0.6,en;q=0.4,pt-BR;q=0.2
Connection:keep-alive
Content-Length:113
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:visitas=5; 0cf3259c57baa4009afba854fca3d67b=dc32f988297cb3c57189ccbcd67c7069; 7a36e8ff9b36e11bfd780a779aebf1f2=4C401412+746+B+3+E55165F145F465B5C165E161413165140104F+94A5746+D1538283B2B74272E225D1618; __zlcmid=NEdVg2JezRIIXT; PHPSESSID=a81316b001465431cab6d3b8a15d118f; __utma=187962025.258322195.1391294013.1391443144.1391507878.8; __utmc=187962025; __utmz=187962025.1391426436.5.2.utmcsr=facebook.com|utmccn=(referral)|utmcmd=referral|utmcct=/; __unam=c61f6f0-143efb22cd0-e2b74ec-8; user_key=1
Host:www.portal-gestao.com
Origin:http://www.portal-gestao.com
Referer:http://www.portal-gestao.com/youbudgetz.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
addList:[{"orcamento":0,"atual":0,"desvio":"","data":"11-02-2014"}]
Response Headersview source
Cache-Control:max-age=0, no-cache, no-store
Connection:close
Content-Encoding:gzip
Content-Length:30
Content-Type:text/html
Date:Tue, 04 Feb 2014 13:57:47 GMT
Server:Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 mod_fcgid/2.3.6
Vary:Accept-Encoding
X-Mod-Pagespeed:0.9.17.7-716
X-Powered-By:PHP/5.3.24
-
I wonder, how are you testing your application when this URL is not working properly (not loading data).
http://www.portal-gestao.com/youbudgetz.html
I believe it was fixed earlier. Am I missing something.
The below url is also not working. throwing SQL error.....
http://www.portal-gestao.com/budget/incluir/json4.php
Erro com o JSON exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10' in /home/portalge/public_html/budget/incluir/json4.php:71 Stack trace: #0 /home/portalge/public_html/budget/incluir/json4.php(71): PDO->query('SELECT DATE_FOR...') #1 {main}
Could you please set it right, so that I could have a look.
-
You need a user account to fetch data.
However, I have enabled data for non-users now, so you can test it.
-
Client side is sending headers and data correctly. I can't see why your server side script is not accepting POST data.
Try to make GET request instead of POST in js and php script.
-
That was the first thing I tried (before asking)..
-
Is GET request also not working for you ?
-
No, the result is exactly the same.
From PHP I get NULL
-
Ok, please try this in ajaxObj
contentType: "application/json; charset=utf-8",
-
In that case, the condition:
if( isset($_POST["addList"]))
returns false.
-
How about creating a simple test.
Create a simple html page include nothing but jQuery. Create a simple PHP page include nothing. Post some data from html to PHP using jQuery.
If the test fails, I guess you need to contact your web hosting service provider.
-
Test passed.
The whole site is a large joomla site, with PHP+MySQL.
I have wasted way too long with this issue, since these are common technologies, it shouldn't be so difficult to solve it...
I'm looking for an answer in stackoverflow, so far it seems Jquery+PHP script isn't ok. I'll post the solution here, perhaps it will help others.
-
I managed to solve the issue quickly with the support of stackoverflow..
It as due to the fact that jQuery encodes json objects as post parameters automagically, so you do not need to amend the json on the way to the server, or decode as json on the server, those things are done for you.
So, in js:
data: { "addList": addList },
And in PHP:
$_POST['addList'][$x]['dataIndx']
-
I'm glad you found the solution and thanks for sharing.
It's strange that JSON.stringify method works correctly on my Test and Prod server for PHP. I'm checking to do it your way now.