views:

121

answers:

3

Hi guys, I'm working using scriptaculous library. However I'm facing some issues with inclusion of the JSON library for the prototype library. It adds a toJSONSTring and parseJSONSTRING method to all objects automatically and frankly this is causing havoc in places. Like I can't seem to use the Ajax Updater function and I suspect its because of this toJSONSTring method that has been attached to my options object which I pass to it.

Is there anyway to unset or atleast somehow remove a function which has been added to the Object.

EDIT:::

Actually I'm trying to make an ajax request and I'm facing an issue in the

Ajax.Updater = Class.create(Ajax.Request,....

part of the prototype library. At the part where its supposed to execute and post an AJAX request it doesn't - especially at:

$super(url, options);

To be precise I'm using this sortable and editable table grid here at this url: http://cloud.millstream.com.au/millstream.com.au/upload/code/tablekit/index.html

Basically you clcik on a table cell to edit it and push the OK button to confirm. Upon clicking the button an ajax request is made.

The editable feature of the table calls the Ajax updater as follows in a submit function:

submit : function(cell, form) {
     var op = this.options;
     form = form ? form : cell.down('form');
     var head = $(TableKit.getHeaderCells(null, cell)[TableKit.getCellIndex(cell)]);
     var row = cell.up('tr');
     var table = cell.up('table');
     var ss = '&row=' + (TableKit.getRowIndex(row)+1) + '&cell=' + (TableKit.getCellIndex(cell)+1) + '&id=' + row.id + '&field=' + head.id + '&' + Form.serialize(form);


     this.ajax = new Ajax.Updater(cell, op.ajaxURI || TableKit.option('editAjaxURI', table.id)[0], Object.extend(op.ajaxOptions || TableKit.option('editAjaxOptions', table.id)[0], {
      postBody : ss,
      onComplete : function() {
       var data = TableKit.getCellData(cell);
       data.active = false;
       data.refresh = true; // mark cell cache for refreshing, in case cell contents has changed and sorting is applied
      }
     }));
    },

The problem is that the request is never made and I keep pushing the OK button to no avail.

EDIT::::::::::::::::

I'm still stumped here - I've even tried calling the Ajax.Updater function on my own and it won't work at all. Its like this function has officially been rendered as useless all of a sudden. I've made the changes you said but all to no avail :( frankly I'm running out of options here - another idea would be to ditch this tablekit and look for something else which has similar functionality in the hopes that THAT MIGHT work!

A: 
delete obj.property

In this case:

delete obj.toJSONSTring;
delete obj.parseJSONSTRING;
Victor
+1  A: 

You can delete anything from an object using "delete":

a.toJSON = function () {};
delete a.toJSON;
a.toJSON() => error: toJSON is not a function
a.toJSON => undefined

However I don't think that what is happening happens because of what you think is happening :) Maybe give more details on the problem you have with Ajax.Updater?


Seen the edit. OK, can you also post the actual line of code that calls Ajax.Updater and, also important, explain in detail how the options object you feed to it is made?

Also, please make sure you're doing something like this:

new Ajax.Updater(stuff)

and NOT just:

Ajax.Updater(stuff)

You NEED to create a new Updater object and use "new" (most probably you're already doing that, just making sure).


OK I'm still not sure what is getting passed to ajax.Updater since you extend stuff that I can't see, but try this: remove the "&" from the beginning of the variable "ss"; in the options object use parameters: ss instead of postBody: ss.

Kaze no Koe
RIghto - check the update please
Ali
Don't that no difference :( any ideas
Ali
Sorry that it didn't work.I suggest you drill down into the objects you're passing to Ajax.Updater with firebug or something like that. I still think Updater chokes on something you're passing to it because I've used it with scriptaculous and had no problems at all. I can't help you much because I can't see enough.
Kaze no Koe
+2  A: 

It sounds like those methods are being added to the prototype of Object. By adding to Object's prototype, the library is automatically giving everything that derives from Object (in other words, everything) those methods as well. You might want to take do some reading on Prototypal inheritance in Javascript to get a better handle on this.

Anyway, you can remove those methods by doing this:

delete Object.prototype.toJSONString;
delete Object.prototype.parseJSONString;
ShZ