Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Created October 7, 2008 00:20
Show Gist options
  • Save tlrobinson/15191 to your computer and use it in GitHub Desktop.
Save tlrobinson/15191 to your computer and use it in GitHub Desktop.
var connection = [[CPURLConnection alloc] initWithRequest:[CPURLRequest requestWithURL:"whatever.php?parameter=blah&etc=yadadada"] delegate:self startImmediately:NO];
[connection start];
...
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data
{
if (connection == aConnection)
{
try
{
var result = CPJSObjectCreateWithJSON(data);
}
catch(e)
{
return [self connection:aConnection didFailWithError: e];
}
// do stuff with result
}
}
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError
{
[self connectionDidFinishLoading:aConnection];
}
- (void)connectionDidFinishLoading:(CPURLConnection)aConnection
{
if (connection == aConnection)
{
connection = nil;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment