1

problem

  • im sending data through ajax

data request payload json sending after form submit

 {
 mis_interests[code]:"R"
 mis_interests[date_opened][month]:" 03-Mar-2016 "
 mis_interests[notes]:" test" 
 }
  • but cannot recieve this data in controller.

js script

            var json_data={
            'mis_interests[code]':interests_val,
            'mis_interests[notes]':texts,
            'mis_interests[date_opened][month]':dateoepend
            }

            jQuery.ajax({
            type:'POST',

            url:'<?php  echo url_for('person/UpdateDatatableInterests')?>',

            contentType: 'application/json; charset=UTF-8',
            dataType: "json",

            data:JSON.stringify(json_data),
            success: function(data){

            console.log(data);



            }
            });
            });

html fields

<form name="something">
<div id="myinterest_wrapper" class="dataTables_wrapper no-footer">
  <select name="mis_interests[code]" id="mis_interests_code" class="mis_interests_code"><option value="test">test</option></select>
  <td id="notes" name="mis_interests[notes]">test</td>

 <td id="dateopened" name="mis_interests[date_opened][month]">03-Mar-2016    </td>


php code

controller action.class.php

public function executeUpdateDatatableInterests(sfWebRequest $request)
{

    var_dump($request->getPostParameter('mis_interests[code]'));

     //output :NULL
}
  • i need to post value selected from dropdown to controller.
  • we are using form , datatable html elements.
  • is there any problem in datatable that is sending null values because i created attribute over datatable that might be culprit.
  • any suggestion is most welcome.

when i tried change in controller

like

$json = $_POST['mis_interests[code]']; 
var_dump(json_decode($json)); 
it shows notice undefined index mis_interests[code] 
afeef
  • 4,396
  • 11
  • 35
  • 65
  • You're sending a JSON request. PHP doesn't automatically decode that data to populate the request globals. You should read the raw POST data and decode it. In SF2, you'd use `$data = json_decode($request->getContent(), true);` – Elias Van Ootegem Apr 21 '16 at 07:41
  • when use core concept like $json = $_POST['mis_interests[code]']; var_dump(json_decode($json)); it shows notice undefined index mis_interests[code] – afeef Apr 21 '16 at 07:49
  • Im thinking problem in using ajax with datatable – afeef Apr 21 '16 at 07:53
  • No, you're sending a JSON _string_, and expecting a POST array. That doesn't fly. check `var_dump(file_get_contents('php://input'));`, that should show a JSON string, `json_decode` that to get an array or object, _then_ you can do something like `$decoded['mis_interests']['code']` to get the data – Elias Van Ootegem Apr 21 '16 at 08:29
  • thanks elias concepts worked – afeef Apr 21 '16 at 08:44

0 Answers0