0

我有这样的功能:

function flush_changes() {
            jQuery('#save-changes').replaceWith('<span id="save-changes">Saving..</span>');
            var changes = new Array();
            for (var i=0; i<edited_users.length; i++) {
                changes.push({
                    id: edited_users[i],
                    first_profession: jQuery('#user_first_profession_' + edited_users[i]).val(),
                    second_profession: jQuery('#user_second_profession_' + edited_users[i]).val()
                });
            }
            jQuery.post("${tg.url('/users/admin_user_professions/save')}",
                        {
                            changed_users: changes,
                            num_of_changed_users: changes.length
                        },
                        function(data) {
                            if (data.result == 'OK') {
                                location.href = location.href;    
                            } else {
                                alert('Error while saving: ' + data.reason);
                            }
                        }, 'json');
        }

当它被调用时,如果我从 localhost 运行应用程序,我可以看到我的数据发送正确,而当我在生产服务器上运行应用程序时,我看到(使用 webkit 检查器)传递的数据如下:

changed_users:[object Object]
num_of_changed_users:1

为什么在生产服务器上我得到“对象对象”?jQuery 库在两个环境中是相同的。

提前致谢!

编辑 这是本地主机上检查器的输出

changed_users%5B0%5D%5Bid%5D:314
changed_users%5B0%5D%5Bfirst_profession%5D:5
changed_users%5B0%5D%5Bsecond_profession%5D:6 num_of_changed_users:1
4

1 回答 1

0

you are sending a json data to server, you must see how your server script get this data and how it decodes them. For example on php I use json_decode for converting json to arrays or objects, may in your production server this process is automatic (by configuration). Also remember to use encodeuricomponent on text when sending data to server, in your case I would do this:

.......
first_profession: encodeURIcomponent(jQuery('#user_first_profession_'+edited_users[i]).val()),
.......

(no need decode of uri on server side is done automatically)

于 2011-02-16T23:13:08.397 回答