显示POST数据使用jQuery? [英] Displaying POST Data with jQuery?

查看:146
本文介绍了显示POST数据使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用闪光灯的摄像头拍照。它的伟大工程和吐回通过POST的URL。

I'm using a flash webcam to take a picture. It works great and spits back a URL via POST.

我编码在PHP,想显示这个职位数据,一旦它:收到,问题是,我不重新加载页面。

I'm coding in PHP and would like to display this POST data once it is recieved, the problem is that I dont re-load the page.

我环顾四周,我不知道动态加载数据的数组。

I've looked around and I'm not sure to dynamically load this array of data.

我应该在哪里寻找? jQuery的?

Where should I be looking? jQuery?

嗯,想通了。闪光的东西我有一个内置的回调函数,所以我只需要从那里将数据追加!

Ah, Figured it out. The Flash thing I have has a built in callback function, so I just have to append the data from there!

推荐答案

jQuery是无法读取任何种类比它出现在URL(GET)等请求数据。您将需要使用PHP(或其他一些服务器端语言)来处理的Flash应用程序创建的响应。

jQuery is not able to read any sort of request data other than that which appears in the URL (GET). You will need to use PHP (or some other server-side language) to handle the response created by the FLash application.

由于您使用的是Flash因为你是在某种程度上处于劣势的过程,因为除非Flash应用程序具有某种JavaScript的PhotoUploaded事件通知,你的页面将不会通知Flash有刚的事实提交图片到你的服务器需要被检索和插入。如果你可以修改Flash应用程序,使外部JavaScript事件,那么你可以继续为程丛夫在他的回答也说明;否则,如果修改Flash应用程序是不是一种选择,那么另一种解决办法是让你的网页发送一个请求到服务器,每隔一段时间(5-10秒左右也许),以检查是否有照片为它显示呢。

Due to the fact that you're using Flash for the process you are at somewhat of a disadvantage because unless the Flash application has some sort of JavaScript "PhotoUploaded" event notification, your page won't be notified that Flash has just submitted a picture to your server which needs to be retrieved and inserted. If you can modify the Flash application to make an external JavaScript event then you can proceed as Frankie has described in his answer; otherwise, if modifying the Flash application is not an option, then another solution would be to have your page send a request to the server every so often (5-10 seconds or so maybe), to check if there is a photo for it to display yet.

最简单的方法来设置轮询以这种方式你的服务器将是确保每个照片上传从Flash中有你的页面知道在初始加载一个独特的,pre确定的标识符。这样,你会简单地用一个AJAX请求ping您的服务器每隔几秒钟,并通过它,为了唯一标识符找到正确的图像应该存在。

The simplest way to setup polling with your server in this fashion would be to make sure that each photo upload from Flash has a unique, pre-determined identifier that your page knows at initial load. You would then simply ping your server every few seconds with an AJAX request and pass it that unique identifier in order to find the right image should one exist.

基本例如:

function GetPhoto() { 
 $.get('/getphoto.php?ID=1541XJ55A6', function(response) { 
    if(response.ImageUrl !== "") {
        $(".profile-image").attr("src", response.ImageUrl);
        if(getPhotoTimer !== undefined) {
            clearInterval(getPhotoTimer);
        }
    }
 });
}

$(document).ready(function() {
    var getPhotoTimer = setInterval("GetPhoto()", 10000); // every 10 seconds
});

这篇关于显示POST数据使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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