Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从web浏览器向本地应用程序发送json命令,该应用程序通过javascript侦听TCP端口5500_Javascript_Json_Tcp_Web - Fatal编程技术网

从web浏览器向本地应用程序发送json命令,该应用程序通过javascript侦听TCP端口5500

从web浏览器向本地应用程序发送json命令,该应用程序通过javascript侦听TCP端口5500,javascript,json,tcp,web,Javascript,Json,Tcp,Web,我有一个监听TCP端口号5500的应用程序,还有一个响应json命令的API。我只想通过JavaScript从web浏览器向应用程序发送json消息,并从应用程序接收json响应 我曾尝试使用JQuery进行如下操作: <!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> </head>

我有一个监听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>

/*将提交处理程序附加到表单*/
$(“#搜索表单”).submit(函数(事件){
/*阻止表单正常提交*/
event.preventDefault();
/*从页面上的元素获取一些值:*/
var$form=$(此),
term='{“type”:“command”,“command”:“call”,“target”:demo@vsee.com"}',
url=”http://localhost:5500";
/*使用post发送数据,并将结果放入div中*/
$.post(url,术语);
});

但它不起作用


有什么想法吗?

假设您的应用程序成功发送响应,您需要对其进行处理。试着这样做:

$.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);
});

您是否在本地应用程序中设置了任何跨源资源共享头?那么,您的问题是什么?它不屈服?