Created
November 11, 2008 23:06
-
-
Save nickjs/24010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation ServerRequester : CPObject | |
{ | |
CPString _returnData @accessors(property=returnData); | |
id _delegate @accessors(property=delegate); | |
} | |
- (void)request:action data:(Object)jsonData | |
{ | |
var actionURL = null; | |
switch(action) | |
{ | |
case "login": | |
actionURL = "multivac/login"; | |
break; | |
} | |
[self executeRequest:actionURL data:jsonData]; | |
} | |
- (void)executeRequest:url data:(Object)jsonData | |
{ | |
var request = [CPURLRequest requestWithURL:url]; | |
[request setHTTPMethod:@"POST"]; | |
[request setHTTPBody:jsonData]; | |
var connection = [CPURLConnection connectionWithRequest:request delegate:self]; | |
} | |
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data | |
{ | |
[self setReturnData:data]; | |
if([self delegate]) | |
[[self delegate] connection:aConnection didReceiveData:data]; | |
} | |
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPString)error | |
{ | |
alert(error); | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)login:(id)sender | |
{ | |
var jsonData = CPJSObjectCreateJSON({"userName": [userName stringValue], "password": [password stringValue]}); | |
requester = [[ServerRequester alloc] init]; | |
[requester setDelegate:self]; | |
[requester request:"login" data:jsonData]; | |
} | |
- (void)connection:(CPURLConnection) didReceiveData:(CPString)data | |
{ | |
var loginData = [requester returnData]; | |
alert(loginData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment