我希望通过 WebOS 平板电脑上使用的 javascript 向本地网络上的 Web 服务页面发送命令。问题是我以前从未这样做过,并且想知道是否有可能一开始就这样做?我可以创建一个 VB.net 来收听 Web 服务调用/网页吗?
我将使用 Dreamweaver 从 phonegap 创建“应用程序”。我正在寻找使用 javascript 将字符串发送到 Web 服务的示例,我可以在 PC 上不断读取该服务,以便根据我在应用程序上按下的按钮根据需要执行任务。
举个例子:
WebOS app >
button pushed in app to call up Internet Explorer >
sends "IE" string to WS >
WS triggers the correct exec to start depending on the string sent to it (IE) >
WS sends back "OK" to WebOS app when program is launched
有没有人有这样的例子?
更新 所以我会在我的javascript中做类似的事情?:
<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
function buttonClicked(str what2Pass)
{
$.ajax({
async : false, /* set as true if you want asynchronous behavior */
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:7777/WebService.asmx/PerformAction",
data: { "webOSCommand" : what2Pass},
dataType: "json",
success: function(data){
alert(true);
}
});
}
<html>
<body>
<input type="button" id="button1" value="run IE on PC" onClick="buttonClicked('IE');" />
</body>
</html>
对于我的 WS,它将是:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Diagnostics
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<ScriptService()> _
Public Class Service
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function PerformAction(byRef webOSCommand as String) As String
Dim oPro As New Process
With oPro
.StartInfo.UseShellExecute = True
.StartInfo.Arguments = "http://www.google.com"
.StartInfo.FileName = "internet explorer.exe"
.Start()
End With
Return "Started"
End Function
End Class