AJAX - The Complete Reference

(avery) #1

626 Part IV: Appendixes


Method

Description

Example

serializeObject(

payload,

object

[,

encodingString

])

Loops through an object of name-value pairs and encodes each using the encoding content-type specified in the encodingString

parameter.

var object = {lastName : "Powell", author : true }; var payload = "name=Thomas";payload = AjaxTCR.data.serializeObject(payload,object);/* name=Thomas&lastName=Powell&author=true */

encodeJSON(

object

)

Translates the given object into a JSON string.

var obj = {firstName : "Gaius", lastName : "Baltar" , traitor : true };var payload = AjaxTCR.data.encodeJSON(obj);/* payload = {"firstName" : "Gaius", "lastName" : "Baltar" , "traitor" : true} */

decodeJSON(

string

)

Translates the given string into a JavaScript object.

payload = '{"firstName" : "Gaius", "lastName" : "Baltar" , "traitor" : true}':var obj = AjaxTCR.data.decodeJSON(payload);/* {firstName : "Gaius", lastName : "Baltar" , traitor : true } */

encodeAsHTML(

string

)

Translates the tags in a string to escaped characters (

<

and

>

). The function

will also translate

\n

into

<br />

.

var result = AjaxTCR.data.encodeAsHTML("I <b> love \n HTML</b>!");/* "I <b> love <br /> HTML </>!" */

serializeXML(

XMLobject

)

Returns any passed XML tree structure back as a string; in other words, serialized.

Given markup like <div id="foo">Test<em>it</em>!</div>var result = AjaxTCR.data.serializeXML(document.getElementById("foo"));/* '<div id="foo">Test<em>it</em>!</div>' */

TABLE

C-8

Useful Data Manipulation Methods for Ajax (

continued

)

http://www.ebooks.org.in

Free download pdf