I got a problem. I am building some kind of a slide editor with AJAX. I have a PHP script which has many functions which can be selected with different GET parameters. Everything works fine. But when I try to post the slides to save them, a value called transformorigin changes from 50% 50% 0 to 50500.
GET slide.php?action=get&id=1
[{"slideid":1,"position":1,"background":{"id":"3","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174513.jpg"},"delay":4000,"timeshift":0,"active":true,"transition2d":[2,7,9],"transition3d":[],"layers":[{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50% 50% 0","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":-80,"offsety":0,"duration":400,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50% 50% 0","easing":{"id":14,"name":"easeInOutQuint"}}},{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50% 50% 0","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":-80,"offsety":0,"duration":400,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50% 50% 0","easing":{"id":14,"name":"easeInOutQuint"}}}]},{"slideid":2,"position":2,"background":{"id":"4","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174608.jpg"},"delay":4000,"timeshift":0,"active":true,"transition2d":[2,7,9],"transition3d":[],"layers":[]}]
POST slide.php?action=post&id=1
[{"slideid":1,"position":1,"background":{"id":"3","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174513.jpg"},"delay":4000,"timeshift":0,"active":true,"transition2d":[2,7,9],"transition3d":[],"layers":[{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50500","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":80,"offsety":0,"duration":400,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50500","easing":{"id":14,"name":"easeInOutQuint"}}},{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50500","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":80,"offsety":0,"duration":400,"delay":0,"fade":true,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"50500","easing":{"id":14,"name":"easeInOutQuint"}}}]},{"slideid":2,"position":2,"background":{"id":"4","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174608.jpg"},"delay":4000,"timeshift":0,"active":true,"transition2d":[2,7,9],"transition3d":[],"layers":[]}]
I don't understand why transformorigin changes after the POST. When I click on the firebug post tab of the post request, it is still 50% 50% 0. But server side I get 50500 when I do a
echo file_get_contents('php://input');
at the begining.
Here is my Javascript/jQuery:
function saveSlides(success,error) {
$.ajax({
url: '/slide.php?action=post&id=' + lid,
type: 'POST',
dataType: 'json',
data: JSON.stringify(slides),
contentType: "application/json; charset=UTF-8",
success: function(data) {
if ("undefined" == typeof(data.error)) {
slides = data;
if (isFunction(success))
success(data);
} else {
if (isFunction(error))
error(data);
}
},error: function() {
if (isFunction(error))
error({"error":{"id":100,"message":"Could not retrieve data."}});
}
});
}
And even when I specify contentType it doesn't change the content type.
Thank you in advance
UPDATE 1:
After encoding everything with JavaScript, this is what I send to the php script:
[{"slideid":"1","position":"1","background":{"id":"3","name":"http%3A//test.com/uploads/1/img/20140729_174513.jpg"},"delay":"4000","timeshift":"0","active":"true","transition2d":[2,7,9],"transition3d":[],"layers":[{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":"80","offsety":"0","duration":"1000","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":"-80","offsety":"0","duration":"400","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}}},{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":"80","offsety":"0","duration":"1000","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":"-80","offsety":"0","duration":"400","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}}}]},{"slideid":"2","position":"2","background":{"id":"4","name":"http%3A//test.com/uploads/1/img/20140729_174608.jpg"},"delay":"4000","timeshift":"0","active":"true","transition2d":[2,7,9],"transition3d":[],"layers":[]}]
This is what I get back from the php script:
[{"slideid":1,"position":1,"background":{"id":"3","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174513.jpg"},"delay":4000,"timeshift":0,"active":false,"transition2d":[2,7,9],"transition3d":[],"layers":[{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":false,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"5025205025200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":80,"offsety":0,"duration":400,"delay":0,"fade":false,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"5025205025200","easing":{"id":14,"name":"easeInOutQuint"}}},{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":80,"offsety":0,"duration":1000,"delay":0,"fade":false,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"5025205025200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":80,"offsety":0,"duration":400,"delay":0,"fade":false,"rotate":0,"rotatex":0,"rotatey":0,"skewx":0,"skewy":0,"scalex":1,"scaley":1,"transformorigin":"5025205025200","easing":{"id":14,"name":"easeInOutQuint"}}}]},{"slideid":2,"position":2,"background":{"id":"4","name":"http:\/\/test.com\/uploads\/1\/img\/20140729_174608.jpg"},"delay":4000,"timeshift":0,"active":false,"transition2d":[2,7,9],"transition3d":[],"layers":[]}]
So now it changes from 50%25%2050%25%200 to 5025205025200.
After i added a urldecode to my php script it returned 50500 again.
UPDATE 2:
Now I am trying to test the php file.
When I do this:
echo file_get_contents('php://input');
die;
I get back the same I send:
[{"slideid":"1","position":"1","background":{"id":"3","name":"http%3A//test.com/uploads/1/img/20140729_174513.jpg"},"delay":"4000","timeshift":"0","active":"true","transition2d":[2,7,9],"transition3d":[],"layers":[{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":"80","offsety":"0","duration":"1000","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":"-80","offsety":"0","duration":"400","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}}},{"background":[],"tag":"h1","content":"Test","style":{"top":"0px","left":"0px"},"transitionin":{"offsetx":"80","offsety":"0","duration":"1000","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}},"transitionout":{"offsetx":"-80","offsety":"0","duration":"400","delay":"0","fade":"true","rotate":"0","rotatex":"0","rotatey":"0","skewx":"0","skewy":"0","scalex":"1","scaley":"1","transformorigin":"50%25%2050%25%200","easing":{"id":14,"name":"easeInOutQuint"}}}]},{"slideid":"2","position":"2","background":{"id":"4","name":"http%3A//test.com/uploads/1/img/20140729_174608.jpg"},"delay":"4000","timeshift":"0","active":"true","transition2d":[2,7,9],"transition3d":[],"layers":[]}]
And when I do this:
$slides = json_decode(file_get_contents('php://input'),true);
print_r($slides);
die;
I get this:
Array
(
[0] => Array
(
[slideid] => 1
[position] => 1
[background] => Array
(
[id] => 3
[name] => http%3A//test.com/uploads/1/img/20140729_174513.jpg
)
[delay] => 4000
[timeshift] => 0
[active] => true
[transition2d] => Array
(
[0] => 2
[1] => 7
[2] => 9
)
[transition3d] => Array
(
)
[layers] => Array
(
[0] => Array
(
[background] => Array
(
)
[tag] => h1
[content] => Test
[style] => Array
(
[top] => 0px
[left] => 0px
)
[transitionin] => Array
(
[offsetx] => 80
[offsety] => 0
[duration] => 1000
[delay] => 0
[fade] => true
[rotate] => 0
[rotatex] => 0
[rotatey] => 0
[skewx] => 0
[skewy] => 0
[scalex] => 1
[scaley] => 1
[transformorigin] => 50%25%2050%25%200
[easing] => Array
(
[id] => 14
[name] => easeInOutQuint
)
)
[transitionout] => Array
(
[offsetx] => -80
[offsety] => 0
[duration] => 400
[delay] => 0
[fade] => true
[rotate] => 0
[rotatex] => 0
[rotatey] => 0
[skewx] => 0
[skewy] => 0
[scalex] => 1
[scaley] => 1
[transformorigin] => 50%25%2050%25%200
[easing] => Array
(
[id] => 14
[name] => easeInOutQuint
)
)
)
[1] => Array
(
[background] => Array
(
)
[tag] => h1
[content] => Test
[style] => Array
(
[top] => 0px
[left] => 0px
)
[transitionin] => Array
(
[offsetx] => 80
[offsety] => 0
[duration] => 1000
[delay] => 0
[fade] => true
[rotate] => 0
[rotatex] => 0
[rotatey] => 0
[skewx] => 0
[skewy] => 0
[scalex] => 1
[scaley] => 1
[transformorigin] => 50%25%2050%25%200
[easing] => Array
(
[id] => 14
[name] => easeInOutQuint
)
)
[transitionout] => Array
(
[offsetx] => -80
[offsety] => 0
[duration] => 400
[delay] => 0
[fade] => true
[rotate] => 0
[rotatex] => 0
[rotatey] => 0
[skewx] => 0
[skewy] => 0
[scalex] => 1
[scaley] => 1
[transformorigin] => 50%25%2050%25%200
[easing] => Array
(
[id] => 14
[name] => easeInOutQuint
)
)
)
)
)
[1] => Array
(
[slideid] => 2
[position] => 2
[background] => Array
(
[id] => 4
[name] => http%3A//test.com/uploads/1/img/20140729_174608.jpg
)
[delay] => 4000
[timeshift] => 0
[active] => true
[transition2d] => Array
(
[0] => 2
[1] => 7
[2] => 9
)
[transition3d] => Array
(
)
[layers] => Array
(
)
)
)
So now I have to decode it somehow.
UPDATE 3:
I had to use encodeURIComponent() inside javascript and urldecode() inside php.
Thank you very much now it works.