46 DOMElement _scriptTag;
57 return [[[
self class] alloc] initWithRequest:aRequest callback:callbackParameter delegate:aDelegate startImmediately:YES];
65 - (id)initWithRequest:(
CPURLRequest)aRequest callback:(
CPString)aString delegate:(
id)aDelegate startImmediately:(BOOL)shouldStartImmediately
72 _delegate = aDelegate;
74 _callbackParameter = aString;
77 [
CPException raise:CPInvalidArgumentException
reason:@"JSONP source specified without callback parameter or CPJSONPCallbackReplacementString in URL."];
79 if (shouldStartImmediately)
92 if ([_delegate respondsToSelector:
@selector(connection:didReceiveData:)])
93 [_delegate connection:
self didReceiveData:data];
95 if ([_delegate respondsToSelector:
@selector(connectionDidFinishLoading:)])
96 [_delegate connectionDidFinishLoading:
self];
103 var head = document.getElementsByTagName(
"head").item(0),
104 source = [[_request URL] absoluteString];
106 if (_callbackParameter)
109 source += _callbackParameter +
"=CPJSONPConnectionCallbacks.callback" + [
self UID];
113 source = [source stringByReplacingOccurrencesOfString:CPJSONPCallbackReplacementString withString:"CPJSONPConnectionCallbacks.callback" + [
self UID]];
118 _scriptTag = document.createElement(
"script");
119 _scriptTag.setAttribute(
"type",
"text/javascript");
120 _scriptTag.setAttribute(
"charset",
"utf-8");
121 _scriptTag.setAttribute(
"src",
source);
123 head.appendChild(_scriptTag);
127 if ([_delegate respondsToSelector:
@selector(connection:didFailWithError:)])
128 [_delegate connection: self didFailWithError: exception];
134 - (void)removeScriptTag
136 var head = document.getElementsByTagName(
"head").item(0);
138 if (_scriptTag && _scriptTag.parentNode == head)
139 head.removeChild(_scriptTag);
Used to implement exception handling (creating & raising).
id initWithRequest:callback:delegate:startImmediately:(CPURLRequest aRequest, [callback] CPString aString, [delegate] id aDelegate, [startImmediately] BOOL shouldStartImmediately)
The main run loop for the application.
void raise:reason:(CPString aName, [reason] CPString aReason)
CPRunLoop currentRunLoop()
An immutable string (collection of characters).
CPJSONPCallbackReplacementString
Allows cross domain connections using JSONP protocol.
CPJSONPConnectionCallbacks
CPDate limitDateForMode:(CPString aMode)
Contains data obtained during a request made with CPURLConnection.
FrameUpdater prototype start
CPJSONPConnection connectionWithRequest:callback:delegate:(CPURLRequest aRequest, [callback] CPString callbackParameter, [delegate] id aDelegate)