i use ajax for my codeeditor. So the POST contains lot of coding-syntax to handle :
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
success: function() {
$('#messagebox').html("<div id='message'>hero!</div>");
}
});
datastring is the val() i pull from a textarea, here it is. yes its random code from a file which get edited in the textarea:
<?php
defined('_JEXEC') or die;
// Import library dependencies
jimport('google.api.facebook');
class smartmech extends GmailApiFb
{
function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
// define language
$this->loadLanguage();
}
?>
This is the process.php
$code = $_POST['code'];
$myFile = "testFile.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $code);
fclose($fh);
THE RESULT is that the file gets created and saved like this:
<?php
defined('_JEXEC') or die;
// Import library dependencies
jimport('google.api.facebook');
class smartmech extends GmailApiFb
{
function __construct(
so it stops at the first “&”. i have no clue why.
Firebug -> Console analyses the post as completely sent, this is why i assume i have to en-/ or decode the ajax before sending.
Any hint is highly appreciated.
Thanks guys for your valuable time
EDIT:
Solution
after further examing the POST from firebug, is saw the newline before starting with the value. (code is the key,
code=
<?php
So i tried to use the mapping instead of a querystring:
data: {code: kode}, //dataString,
this was the difference which makes the code working like a charm.
for completeness to make sense
var kode = editor.getValue();
var dataString = 'code='+kode;
getValue() is a custom function to get the val() from an element.
Anyone knows why this difference?
I’d be interested in seeing the actual post; particularly, if the parameters are being sent correctly. “data” should be either a serialized set of key:value pairs in the form of a query string (
myvar=foo&myothervar=bar) or it can be a map ({ myvar: "foo", myothervar: "bar" }). If you are just grabbing a string from .val() like “foo” and trying to pass it, it might be poorly-formed upon sending. In other words, if you are grabbing “foo”, it might be trying to send “?foo=” instead of “?myvar=foo“.I have to admit, that’s a guess; I’m not in a good environment for testing AJAX right now.