Note that there are some explanatory texts on larger screens.

plurals
  1. POMake JSON obj and send it via jQuery AJAX to PHP and respond to it
    primarykey
    data
    text
    <p>i'm working on this now for about 2-3 hours and i cant find where i'm doing it wrong. this is my jQuery that is going to build an object:</p> <pre><code>var data = {cat:[],count:[],size:[],type:[],print:[]}; $("#Cat-list option").each(function() {data.cat.push($(this).val());}); $("#Count-list option").each(function() {data.count.push($(this).val());}); $("#Size-list option").each(function() {data.size.push($(this).val());}); $("#Print-list option").each(function() {data.print.push($(this).val());}); $("#Type-list option").each(function() {data.type.push($(this).val());}); </code></pre> <p>after this i will have an object named data. when i convert the obj to JSON by <code>var jsonString=JSON.stringify(data);</code> it gives me something like this:</p> <pre><code>{ "cat":["Cart Visit","Bag","Envelope","Tracket","Brosur"], "count":["1000","2000","4000","5000","?????"], "size":["S","M","L","X"], "type":["?? ??","??? ? ??","????"], "print":["????","???????","????"] } </code></pre> <p>then i use jQuery Ajax to send the jsonstring to my php file like this:</p> <pre><code>$.ajax({ type: "POST", url: 'update_db.php', data: jsonString, contentType: "application/json; charset=utf-8", success: function(result) { $( "#alert").html( result ); } }); </code></pre> <p>and finally i'm trying to recieve the data with php script. i dont know how to fetch the data for this i tried it with 'jsonstring' and 'data':</p> <pre><code>$json = json_decode( $_POST['jsonstring']); $data = json_decode( $_POST['data']); var_dump($json); var_dump($data); </code></pre> <p>but both are "NULL". What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload