所以我有将数据提交到 PHP 脚本的代码。这个想法是代码将数据插入数据库。如果成功发生,则返回的字符串将为“SUCCESSFUL”,否则为“Failed”。现在我想当成功返回值时,它会加载另一个视图,说谢谢(标签)。我怎样才能做到这一点?
代码:
(IBAction)saveDataAction:(id)sender {
NSString *lEventTitle = [NSString stringWithFormat:@"var=%@",eventTitle.text];
NSString *lEventDesc = [NSString stringWithFormat:@"var=%@",eventDescription.text];
NSString *lEventCity = [NSString stringWithFormat:@"var=%@",eventCity.text];
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"title=%@&description=%@&city=%@",lEventTitle ,lEventDesc,lEventCity];
myRequestString = [myRequestString stringByReplacingOccurrencesOfString:@"var=" withString:@""];
NSLog(@"%@",myRequestString);
// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.xsysdevelopment.com/ios/form.php"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);
if ([response rangeOfString:@"SUCCESSFUL"].location == NSNotFound)
{
//here??
}
}
我在这里先向您的帮助表示感谢