When I'm passing the two variables to my php I get Notice: Undefined index : name
& Notice: Undefined index : parsed
.
When I'm adding an echo
for each variable, I get nothing.
Nothing is added in my database.
name = "myName";
parsed = someCode.toJSON();
parsed = JSON.stringify(parsed, null, '\t');
parsed = parsed.replace(/[
\t]+([\d\.e\-\[\]]+)/g, '$1');
$.ajax({
url: 'js/function/scriptSave.php',
type: 'POST',
dataType: 'JSON',
data: {name : name, parsed : parsed},
success: function(result) {
alert("Success");
},
error: function(err){
alert('Error'+err);
}
});
The Ajax always returns me the error case : Error [object Object]
When I'm replacing my variables with text, everything works:
data: {name : 'name', parsed : 'parsed'}
And when I remove the json variable only it works. I really don't understand what happens here..
[EDIT]
The variable containing the name is ok. But when I only put the variable containing the json, it doesn't work. But what is the problem with this variable ?
So far, I have tried:
var obj = {}; obj.name = 'myName'; obj.parsed = someCode.toJSON();
{data : JSON.stringify(obj)}
///////
{'name' : name, 'parsed' : parsed}
///////
{parsed : JSON.stringify(parsed)}
Here's my php:
<?php
if (!@mysql_connect('localhost', 'user', 'pwd')) {
die("Error");
} else {
mysql_select_db('database');
}
$parsed = $_POST["parsed"];
$name = $_POST["name"];
mysql_query("INSERT INTO object(name, parsed) VALUES ('".$name."', '".$parsed."')");
?>
[EDIT 2]
When I'm changing dataType from JSON
to TEXT
the ajax is in success case, but nothing is inserted in DB...
When I'm looking in my devTools in chrome everything semm to be ok :
General
Request Method :POST
Status Code: 200 OK
Response Headers
Content-Type: text/html
Request Headers
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Form Data
name : myName
parsed : {"another" : "value"}
[EDIT 3]
The problem seems to come from the json size... When I'm excluding some fields, everything seems to work. The problem is that in my databse, my field which will contain my JSON, is a LongText... The JSON size doesn't have to be the problem..