Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

replace jquery-json with es5 equivalents #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## ?

* Replace usage of `$.evalJSON` and `$.toJSON` with ES5-compliant `JSON.parse` and `JSON.stringify` (Brian Moseley)

## 0.0.2

* Add support for optional protocols parameter in WebSocket constructor (Valentin Kunz)
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ but no activity in the code since 2010.
<input id="message" type="text"/>
<script src="http://www.google.com/jsapi"></script>
<script>google.load("jquery", "1.3")</script>
<script src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js"></script>
<script src="https://raw.github.com/douglascrockford/JSON-js/master/json.js"></script>
<script src="https://raw.github.com/dchelimsky/jquery-websocket/v0.0.2/jquery.websocket.js"></script>
<script>
var ws = $.websocket("ws://127.0.0.1:8080/", {
Expand All @@ -58,6 +58,15 @@ but no activity in the code since 2010.
</body>
</html>

## Note on ECMA5cript 5 JSON API compatibility

Version 0.3 and below explicitly depended on the [jquery-json](https://code.google.com/p/jquery-json/) library to define the `$.evalJSON` and `$.toJSON` methods. This requirement has been replaced in subsequent versions by a dependency on the JSON parsing and serialization API defined in ECMAScript5 ([described thoroughly here](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/)).

When upgrading from 0.0.3, you must do one of the following:

1. Replace your usage of jquery-json with a library that defines `JSON.parse` and `JSON.stringify` for browsers that do not support them natively. json2.js from the [JSON-js](https://github.com/douglascrockford/JSON-js) library is a good choice.
2. Provide your own implementations of those methods or otherwise deal on your own with browsers that do not support them natively.

# License

The MIT License (MIT)
Expand Down
4 changes: 2 additions & 2 deletions jquery.websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.bind('close', settings.close)
.bind('message', settings.message)
.bind('message', function(e) {
var m = $.evalJSON(e.originalEvent.data);
var m = JSON.parse(e.originalEvent.data);
var h = settings.events[m.type];
if (h) h.call(this, m);
});
Expand All @@ -37,7 +37,7 @@
var m = {type: type};
m = $.extend(true, m, $.extend(true, {}, settings.options, m));
if (data) m['data'] = data;
return this._send($.toJSON(m));
return this._send(JSON.stringify(m));
};
$(window).unload(function(){ ws.close(); ws = null; });
return ws;
Expand Down