将数据从浏览器发送到服务器并返回 [英] Sending data from a browser to a server and back

查看:314
本文介绍了将数据从浏览器发送到服务器并返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C ++开发人员,我没有真正跟进任何与网络相关的开发很长时间。我有这个项目,我想实现,真的作为一个目标赶上这些技术。我的项目是这样:

I am C++ developer and I haven't really followed up on any development related to the web for a very long time. I have this project I would like to implement, really as a goal to sort of catch up on these technologies. My project is this:


  • 在浏览器中显示一些内容(例如使用canvas和WebGL的3D场景的内容)页面上的按钮。当点击按钮时,将数据发送到服务器(例如摄像机位置),在服务器上渲染图像(使用一些离线的高质量渲染解决方案),将图像返回到浏览器,最后,显示它

我相信我可以用WebGl,canvas和HTML等简单的东西填补空白。有一些这些技术,我可以学习。我完全失去的是所使用或需要的技术,例如将数据发送到服务器,在那里处理数据,并将一些结果发送回客户端。现在我已经做了一些关于Web的研究,但是在那里有很多的研究,它只是真的很难知道在哪个方向去。他们是吨图书馆,API,技术等。

I believe I can fill up the gaps with simple things such as WebGl, canvas and HTML 5. I am familiar with some of these techniques and I can learn. Where I am completely lost is the technology that is used or needed to do things such as sending the data to a server, having them processed there, and sending some result back to the client. Now I have done some research on the Web of course, but the is SO MUCH STUFF out there, that it's just REALLY hard to know in which direction going. They are tons of libraries, APIs, bits of technologies, etc.

我怀疑我需要使用JavaScript,DOM,HTML5的一些组合...但会欣赏如果人们以前做过或知道这应该如何工作,可以指向我正确的方向。我真的寻找一些基本的东西,如果可能不使用某种第三方API。我不想做复杂的东西简单,发送数据,处理,发送回显示。我的目标是理解原则,不要做某事专业或超级强大。

I am suspecting I need to use some combination of JavaScript, DOM, HTML5 ... but would appreciate if people having done that before or knowing how this should work, could point me to the right direction. I am really looking for something basic, and IF possible not using some sort of 3rd party APIs. I don't want to do something complicated just simple, send data, process, send back for display. My goal is to understand the principles, not to make something professional or super powerful. I am doing this with an educational goal in mind (to learn and understand).

我读了关于RESTFUL,但我仍然不确定这是否是我需要的。真的,如果有人可以简单地描述我的基本技术组件,我需要这个项目,指向我的文档,教程,例子,给我的位和我应该阅读的技术的名称,这将是非常感谢。

I read about RESTFul but I am still unsure if this is what I need. Really if someone can either simply describes me the basic technology components that I need for this project, point me to documents, tutorials, examples, give me the name for the bits and pieces of technologies I should read about, it would be greatly appreciated.

我意识到这个问题的范围非常大(我应该做之前的家庭工作,而不是有知识的年份赶上)。我相信虽然这个问题可能是很多人感兴趣的。

I realize the scope of this question is very large (and that I should have done my home work before instead of having years now of knowledge to catch up on). I believe though this question can be of great interest to many. And I also promise that I will post my findings and why not my working example when I have one figured out and working.

谢谢你。

推荐答案

不是一个答案,只是建议/想法包括代码。结构化/格式化的注释。

NOT AN ANSWER, just suggestions/ideas that include code. A structured/formatted comment.

不确定如何在C ++中使用/编写它们,但这只是一个渲染HTML和实​​现JavaScript代码的问题。

Unsure how to use/code them in C++, but this is just an issue of rendering HTML and implementing javascript code.

基本要素是:

加载jQuery库。一种方法是:

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>

对您的jQuery脚本使用JavaScript代码块

<script type="text/javascript">
    $(document).ready(function() {

        $('#mybutton').click(function() {
            var pic = $('image_selector').val();
            $.ajax({
                type: "POST",
                url: "ind.php",
                data: "img=" + pic
            })
            .done(function(recd) {
                $('#txtHint').html(recd);
            });
        }); //END mybutton click

    }); //END document.ready
</script>

我不知道你如何发送一个pic作为var,

I don't know how you would send a pic as a var, or how to structure that, but you get the basic gist...

在服务器端,它的工作原理是这样的(使用PHP for example):

On the server side, it works like this (using PHP for eg):

<?php
    $image = $_POST['img'];

    //Do something with the received image

'm思考它,你发送一个图像(我以前没有做过的),所以我不认为你可以发送它像文本或JSON对象...你可能需要发布它与 enctype ='multipart / form-data 属性的文件上传,就像使用表单上传时一样?只要猜测。

Actually, now that I'm thinking about it, you are sending an image (something I haven't done before), so I don't think you can just send it like text or a JSON object... You may need to post it with the enctype='multipart/form-data attribute for file uploads, as you do when using a form for uploads? Just guessing.

无论如何,这不是为了回答你的问题,只是给你一些提示,看看更进一步。

Anyway, this is not intended to answer your question, just to give you some hints as to where to look further.

查看AJAX基本知识的这些简单示例:

See these simplistic examples for the basics of AJAX:

一个简单的示例

更多复杂的例子

根据下拉列表中的选择填充下拉菜单2

这篇关于将数据从浏览器发送到服务器并返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆