Author Topic: PHP add, update, delete  (Read 25997 times)

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6156
    • View Profile
Re: PHP add, update, delete
« Reply #15 on: February 04, 2014, 08:26:12 pm »
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.


nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #16 on: February 04, 2014, 08:35:26 pm »
That was the first thing I tried (before asking)..

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6156
    • View Profile
Re: PHP add, update, delete
« Reply #17 on: February 04, 2014, 08:37:42 pm »
Is GET request also not working for you ?

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #18 on: February 04, 2014, 08:39:32 pm »
No, the result is exactly the same.

From PHP I get
Quote
NULL

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6156
    • View Profile
Re: PHP add, update, delete
« Reply #19 on: February 04, 2014, 08:55:59 pm »
Ok, please try this in ajaxObj

contentType: "application/json; charset=utf-8",


nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #20 on: February 04, 2014, 09:10:47 pm »
In that case, the condition:

Code: [Select]
if( isset($_POST["addList"]))     
returns false.


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6156
    • View Profile
Re: PHP add, update, delete
« Reply #21 on: February 05, 2014, 09:57:11 am »
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.

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #22 on: February 05, 2014, 03:26:26 pm »
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.

nuno.nogueira

  • Pro Economy
  • Jr. Member
  • *
  • Posts: 95
    • View Profile
Re: PHP add, update, delete
« Reply #23 on: February 05, 2014, 07:54:32 pm »
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:

Quote
data: { "addList": addList },

And in PHP:
Code: [Select]
$_POST['addList'][$x]['dataIndx']

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6156
    • View Profile
Re: PHP add, update, delete
« Reply #24 on: February 05, 2014, 08:30:27 pm »
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.


« Last Edit: February 06, 2014, 12:23:00 am by paramquery »