简体   繁体   English

JavaScript发送和接收跨服务器数据

[英]JavaScript send&receive data cross server

I taught myself programming so my knowledge is very fragmented and now I have encountered a fragment I know nothing about. 我自学编程,因此我的知识非常分散,现在遇到了我一无所知的片段。 Sending and receiving Date. 发送和接收日期。 In addition I want to do it across domains. 另外,我想跨域进行。 I know about the security policies that prohibit this but have read about some solutions. 我知道禁止这样做的安全策略,但已经阅读了一些解决方案。 I still can't make sense of it in relation to my challenge. 对于我的挑战,我仍然无法理解。

What I want to do: 我想做的事:

I want to build a plugin that sends data to my server when a function is called. 我想构建一个在调用函数时将数据发送到服务器的plugin The function is bound to an event listener. 该函数绑定到事件侦听器。 this plugin contains of a little html-form and some js in the back. 这个plugin在后面包含一些html形式和一些js。 i want to send json or simular. 我想发送json或类似符号。 my questions: 我的问题:

I) how do I send data to an other server? 我)如何将数据发送到其他服务器?

II) how do I receive this data? II)我如何接收这些数据? I know about parsing and dom but all I did so far is handle requested data. 我了解解析和dom但到目前为止,我所做的只是处理请求的数据。 now this data is posted to my server-app without me knowing beforehand. 现在,这些数据已发布到我的服务器应用程序中,而我并没有事先知道。 the data is used to update a DB. 数据用于更新数据库。 the backend is coded in JS or python. 后端是用JS或python编码的。 I would prefer JS for compatability reasons. 由于兼容性原因,我更喜欢JS

III) how can I test the cross server connection on my local machine? III)如何在本地计算机上测试跨服务器连接? especially without an active internet-connection? 特别是没有活动的互联网连接?

I don't expect a complete guide or the code i need. 我不希望有完整的指南或所需的代码。 just the resources and where to get the knowledge-chunks I need to build this. 只是资源和获取知识块的地方,我需要构建它。

Thanks a bunch in advance! 提前谢谢一堆!

I) how do i send data to an other server? 我)如何将数据发送到其他服务器?

You may use AJAX (or jQuery.ajax a more convenient way) 您可以使用AJAX(或使用jQuery.ajax更方便的方式)

II) how do i receive this data? II)我如何接收这些数据? i know about parsing and dom but all i did so far is handel requested data. 我知道解析和dom,但到目前为止,我所做的只是处理请求的数据。 now this data is posted to my server-app without me knowing beforehand. 现在,这些数据已发布到我的服务器应用程序中,而我并没有事先知道。 the data is used to update a DB. 数据用于更新数据库。 the backend is coded in JS or python. 后端是用JS或python编码的。 i would prefer JS for compatability reasons. 由于兼容性原因,我更喜欢JS。

As long as you send some data via AJAX, the browser makes a HTTP call and you could receive the data from server-side. 只要您通过AJAX发送一些数据,浏览器就会发出HTTP调用,您就可以从服务器端接收数据。 Both JS or python would compatible with your client-side javascript and seldom do there have compatibility issue. JS或python都将与您的客户端javascript兼容,并且很少有兼容性问题。

III) how can i test the cross server connection on my local maschine? III)如何在本地机器上测试跨服务器连接? especially without an active internet-connection? 特别是没有活动的互联网连接?

localhost and 127.0.0.1 is treated as different host and I usually use these to test cross server scenario. localhost127.0.0.1被视为不同的主机,我通常使用它们来测试跨服务器方案。 One issue of AJAX is that browser usually disallow Cross Domain calls unless you specify Access-Control-Allow-Origin headers . AJAX的一个问题是,除非您指定Access-Control-Allow-Origin标头,否则浏览器通常不允许跨域调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM