1 (edited by Fromzon 2011-02-07 4:00:10 AM)

Topic: [BUG] Array bug ( detailed bugreport )

There are still some issues with passing arrays from JavaScript to PHP since the implentation of JSON.
I've seen there have been people posting the same problem, but nobody has done it in any detail.

Therefore, I've decided to create a simple test project and I've copied them as 2 projects: 1 project uses Xajax version 0.5, the other uses Xajax version 0.6

source code


JavaScript part:

function sendCars(){
    var cars = new Array();
    var car1 = new Array();
    car1['id'] = 1;
    car1['name'] = "Toyota";
    car1['color'] = "red";
    var car2 = new Array();
    car2['id'] = 2;
    car2['name'] = "Mitsubishi";
    car2['color'] = "blue";
    cars[1] = car1;
    cars[2] = car2;

PHP Part:

function showGarage($arrCars){
    $objResponse = new xajaxResponse(); 
    return $objResponse;

Here is the code which I'll use to trigger the function:

<a href="#" onclick="sendCars();">click here</a>

Ok thus far the code.

The Test Case and bug triggering

I have 2 projects, project 1 uses version 0.5 ( XML )
Project 2 uses version 0.6 ( JSON ).

In project 1:
Clicking on "click here" results in an alert box saying "red"

In project 2:
Clicking on "click here" results in an alert box saying "null"
--> this shows there are problems with Arrays

I have no idea how to solve it, but I'll try to give some extra information:

The guilty part

In project 1, the following information is being posted:

xjxargs[]    <xjxobj><e><k>1</k><v><xjxobj><e><k>id</k><v>N1</v></e><e><k>name</k><v>SToyota</v></e><e><k>color</k><v>Sred</v></e></xjxobj></v></e><e><k>2</k><v><xjxobj><e><k>id</k><v>N2</v></e><e><k>name</k><v>SMitsubishi</v></e><e><k>color</k><v>Sblue</v></e></xjxobj></v></e></xjxobj>
xjxfun    showGarage
xjxr    1297046771177

And this is being received:

<?xml version="1.0" encoding="utf-8" ?><xjx><cmd cmd="al">Sred</cmd></xjx>

In project 2, the following gets posted:

xjxargs[]    [null,[],[]]
xjxfun    showGarage
xjxr    1297046881919

==> This already shows the problem clearly I'd say

And obviously this is being received:


End of report

You guys are doing an awesomely great job here, the power of Xajax is enormous.
So it would be great if you could fix this bug big_smile
Thank you for Xajax.

Re: [BUG] Array bug ( detailed bugreport )

Any news on this bug?

Re: [BUG] Array bug ( detailed bugreport )

I understand your confusion as it worked in 0.5 but not in 0.6.1. That was a floor in 0.5 not in 0.6.1

Associative arrays don't really exist in js. Have a quick look here for an explanation http://stackoverflow.com/questions/4425 … ay-to-json

All you need to do to remedy your code is define car1 and car2 as objects rather than arrays i.e. var car1 = {}; and var car2 = {};

Re: [BUG] Array bug ( detailed bugreport )

Hi mungushume,
I just applied a software update on my application with your proposed object-solution,
and everything works brilliantly now with Xajax 0.6

Many thanks for your help !  :-)

Re: [BUG] Array bug ( detailed bugreport )

@Fromzon You're welcome.
A post with as much detail as you provided deserves the help!
If only the users of some of my software would provide as much info when they encounter a problem... wink

Re: [BUG] Array bug ( detailed bugreport )

same issue here sad

Re: [BUG] Array bug ( detailed bugreport )

there are 2 js files changed now they solve the problem

https://github.com/romacron/Xajax-Proje … h/xajax_js

an extended example with multi-dimensions array located at http://xajax.romacron.de/tests/formSubmissionTest.php