从web浏览器通过javascript向侦听TCP端口5500的本地应用程序发送json命令
Send json command to local application that listens to TCP port 5500 via javascript from web browser
我有一个应用程序,它监听TCP端口号5500,并有一个响应json命令的API。我只想通过JavaScript从web浏览器向应用程序发送json消息,并从应用程序接收json响应。
我曾尝试使用JQuery来做到这一点,如下所示:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form action="/" id="searchForm">
<input type="submit" value="Call" />
</form>
<!-- the result of the search will be rendered inside this div -->
<div id="result"></div>
<script>
/* attach a submit handler to the form */
$("#searchForm").submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get some values from elements on the page: */
var $form = $( this ),
term = '{"type" : "command","command" : "call","target" :"demo@vsee.com"}',
url = "http://localhost:5500";
/* Send the data using post and put the results in a div */
$.post( url, term);
});
</script>
但它不起作用,
有什么想法吗?
假设你的应用程序成功发送了响应,你需要对它做点什么
$.post( url, term, function(response){
// I'm assuming you're getting a plain text response
// If it's JSON, you'll want to parse it first
$('#result').text(response);
});
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- angular 1.5应用程序中的导航栏
- 在Web应用程序中使用Highcharts javascript
- angularjs+rails应用程序中未显示模板
- 使用acess代币登录Facebook,并通过网络应用程序离线发布
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 使用谷歌应用程序脚本将服务器端数据表返回到客户端
- Angularjs-utils高亮过滤器在搜索时破坏应用程序
- 在phonegap应用程序内部重定向不起作用
- 使用谷歌应用程序脚本从工作表中获取值并将其显示在文本框中
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- Node.js正在更改应用程序以使用集群模块
- 在openshift node js应用程序中获取请求
- 如何在Facebook上的iframe应用程序中使后退按钮返回到上一页
- 从web浏览器通过javascript向侦听TCP端口5500的本地应用程序发送json命令