- 更新 - 我最初发布的是 firefox 错误,chrome 错误消息更有用,所以我更新了它的名称
(firefox) - worklight.js 中无效的“输入”操作数配置文件
(chrome)- TypeError:无法使用“in”运算符在 null 中搜索“SUPPORT_WL_SERVER_CHANGE”
我见过与此类似的问题,没有人回答过,也没有人提供重现结果所需的所有代码。
我在使用 Firefox 和 Chrome 时收到不同的消息。所以我更新了标题以显示两者。
重现:
创建一个新的worklight项目,并在该项目中应用 创建一个新的 HTTP 适配器,将其命名为 myRESTAdapter
将 index.html 替换为:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>angular_test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=0.5, minimum-scale=2.0, user-scalable=0">
<script>window.$ = window.jQuery = WLJQ;</script>
<script>
function mobGmapLatLng(pAddress) {
var invocationData = {
adapter : 'myRESTAdapter',
procedure : 'getGmapLatLng',
parameters : [ pAddress ]
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : function(result){
console.debug("good");
var httpStatusCode = result.status;
if (200 == httpStatusCode) {
var invocationResult = result.invocationResult;
var isSuccessful = invocationResult.isSuccessful;
if (true == isSuccessful) {
var lat = invocationResult.lat;
var lng = invocationResult.lng;
alert("Success: lat=" + lat + " lng=" + lng);
}
else {
alert("Error. isSuccessful=" + isSuccessful);
}
}
else {
alert("Error. httpStatusCode=" + httpStatusCode);
}
},
onFailure : function(result){
console.debug("bad");
}
});
}
</script>
</head>
<body>
Hello Worklight with getGmapLatLng
<p>
<button onclick="mobGmapLatLng( '11501 Burnet Rd, Austin, TX, USA' )">Austin, TX, USA</button>
</p>
<p>
<button onclick="mobGmapLatLng( '4250 South Miami Boulevard, Durham, NC, USA' )">Durham, NC, USA</button>
</p>
<p>
<button onclick="mobGmapLatLng( '1681 Route des Dolines, 06560 Valbonne, France' )">Valbonne, France</button>
</p>
<p>
<button onclick="mobGmapLatLng( 'Shefayim 60990, Israel' )">Shefayim, Israel</button>
</p>
<p>
<button onclick="mobGmapLatLng( '399 Ke Yuan Lu, Shanghai, China' )">Shanghai, China</button>
</p>
</body>
</html>
接下来在您的适配器中将 myRESTAdapter.xml 替换为:
<?xml version="1.0" encoding="UTF-8"?>
<wl:adapter name="myRESTAdapter"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>myRESTAdapter</displayName>
<description>myRESTAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>http://maps.googleapis.com</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
</connectivity>
<procedure name="getGmapLatLng"/>
</wl:adapter>
并将 myRESTAdapater-impl.js 替换为:
function getGmapLatLng(pAddress) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/geocode/json',
parameters : {
'address' : 'plaza 3 one nationwide blvd columbus oh',
'sensor' : 'false' // hard-coded
}
};
var response = WL.Server.invokeHttp(input);
// Extract latitude and longitude from the response.
var type = typeof response;
if ("object" == type) {
if (true == response["isSuccessful"]) {
// Drill down into the response object.
var results = response["results"];
var result = results[0];
var geometry = result["geometry"];
var location = geometry["location"];
// Return JSON object with lat and lng.
return location;
}
else {
// Returning null. Web request was not successful.
return null;
}
}
else {
// Returning null. Response is not an object.
return null;
}
}
右键点击 index.html 并选择 Run As-> preview 打开 Firebug ,以便您可以看到错误消息:worklight.js 中的“in”操作数配置文件无效 单击其中一个按钮,您将在 firebug 中看到错误消息
*** 注意:我必须进行一些更改才能在公司防火墙后运行,我认为它应该粘贴并运行,但我目前无法按原样对其进行测试。
** 注 2:我几乎可以肯定,我以前成功运行过这段确切的代码,但我无法弄清楚为什么有时我会收到错误,有时却能正常工作
使用 worklight 6.3.0 测试 适配器代码运行正常,并在我使用 run as->invoke mobilefirst procedure
调用它时返回正确的数据行号:worklight.js 中的 5059
最佳答案
我重建了项目,让它开始工作,在查看工作项目和我的项目之间的差异时,这是我在原始代码中丢失的代码部分:
<script>
var wlInitOptions = {
};
if (window.addEventListener) {
window.addEventListener('load', function() {
WL.Client.init(wlInitOptions); }, false);
} else if (window.attachEvent) {
window.attachEvent('onload', function() {
WL.Client.init(wlInitOptions); });
}
</script>
关于javascript - 类型错误 : Cannot use 'in' operator to search for 'SUPPORT_WL_SERVER_CHANGE' in null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370713/