iOS アプリケーションでリモート プロシージャを実行するために uiwebview を使用しています。これらのリモート プロシージャは、ローカル http サーバーに対して特定の ajax 要求を実行できます。これにより、正しい応答ハンドラーが実行されます。これは、「xmlhttprequest Exception 101」につながるスクリプト全体を再度実行しようとするまで正常に機能します
ハンドラー ajax:
NSString* makeHTMLwithRegisteredHandlers(NSString* serverurl)
{
NSMutableString* output = [NSMutableString new];
if(registeredHandlers != nil)
{
for(int i=0;i<registeredHandlers.count;i++)
{
NSString* scriptfunc = [AbstractRemoteProcedure makeGetJSFromClass:[registeredHandlers objectAtIndex:i]];
[output appendFormat:@"\nfunction %@(paramdata) { \n",scriptfunc];
[output appendString:@"\t$.ajax({ \n"];
[output appendString:@"\t\ttype: \"POST\", \n"];
[output appendFormat:@"\t\turl: \"%@/%@\", \n",serverurl,scriptfunc];
[output appendString:@"\t\tasync:false, \n"];
[output appendString:@"\t\tprocessData: false, \n"];
[output appendString:@"\t\tdata: paramdata, \n"];
[output appendString:@"\t\terror: function(xhr, ajaxOptions, thrownError) { \n"];
[output appendString:@"\t\t\talert(\"runtime exception:\"+thrownError);\n"];
[output appendString:@"\t\t\tbreakmyJS();\n"];
[output appendString:@"\t\t},\n"];
[output appendString:@"\t\tsuccess: function(data) { \n"];
[output appendString:@"\t\t\tresult = data; \n"];
[output appendString:@"\t\t}\n"];
[output appendString:@"\t});\n"];
[output appendString:@"\treturn result;\n} \n"];
}
}
return output;
}
サーバー側スクリプト:
function onConnect()
{
//device just connected to network
}
function onRetrieve()
{
var req = new Object();
req.url = servertoRequestFrom;
req.usr = deviceIdentifier();
req.pwd = deviceSecret();
var res = HttpCrossDomainSend(jQuery.stringify(req));
var decoded = jQuery.parseJSON(res);
makeSheet(decoded);
}
function onSend()
{
}
function onAuthorize(action)
{
return false;
}
デバッグ ログ:
2012-04-20 17:03:37.290 myApplication[7066:707] server running:http://127.0.0.1:900/
2012-04-20 17:03:39.464 myApplication[7066:707] InitializeRuntimeProcedure start
2012-04-20 17:03:39.466 myApplication[7066:707] InitializeRuntimeProcedure done
2012-04-20 17:03:39.492 myApplication[7066:707] DeviceTypeProcedure start
2012-04-20 17:03:39.493 myApplication[7066:707] DeviceTypeProcedure done
2012-04-20 17:03:39.515 myApplication[7066:707] DeviceVersionProcedure start
2012-04-20 17:03:39.516 myApplication[7066:707] DeviceVersionProcedure done
2012-04-20 17:03:39.537 myApplication[7066:707] DeviceNameProcedure start
2012-04-20 17:03:39.539 myApplication[7066:707] DeviceNameProcedure done
2012-04-20 17:03:39.560 myApplication[7066:707] DeviceIdentiferProcedure start
2012-04-20 17:03:39.563 myApplication[7066:707] DeviceIdentiferProcedure done
2012-04-20 17:03:39.583 myApplication[7066:707] DeviceSecretProcedure start
2012-04-20 17:03:39.586 myApplication[7066:707] DeviceSecretProcedure done
2012-04-20 17:03:39.608 myApplication[7066:707] CrossDomainRequest start
2012-04-20 17:03:40.616 myApplication[7066:707] CrossDomainRequest done
2012-04-20 17:03:40.653 myApplication[7066:707] MakeSheetProcedure start
2012-04-20 17:03:40.662 myApplication[7066:707] MakeSheetProcedure done
2012-04-20 17:03:51.841 myApplication[7066:575b] onRetrieve();
onSend();
2012-04-20 17:04:02.026 myApplication[7066:707] DeviceTypeProcedure start
2012-04-20 17:04:02.028 myApplication[7066:707] DeviceTypeProcedure done