开发者

PHP auction script using AJAX [closed]

开发者 https://www.devze.com 2023-03-29 12:10 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post.
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 7 years ago.

Improve this question 开发者_运维问答

Is it possible to create a auction site in PHP using AJAX to refresh the page once a user has entered a higher amount of money.

I can handle the PHP side of it okay but I was wondering if AJAX can really be used so that it refreshes often without putting a lot of strain on server resources?

I also plan to use JQuery to implement AJAX as this makes the job a whole lot easier. Anybody have any code examples that you think could be used?

Any help would be appreciated/

Thanks!


var currentHighestBid=0;
setTimeOut(getHighestBid,5000); //5000ms wait before polling for a better price

function getHighestBid()
{

    $.ajax(
    url: url, // ur php end point,
    type: "GET"
    data: {}   //json data if you want to send anything as a querystring parameter to your servre
    dataType:"json"
    success: function(response)
    {

        if(response.currentMaxBid>currentHighestBid)
        {
        currentHighestBid=response.currentMaxBid;
        //code to update your markup
        }

    }

});

Hope that made sense..

Read abt json in php


Polling would work as "zzzz" mentioned. Comet (Push based instead of Polling) would be a nicer/better solution for this use case. However PHP is not really good at this with high traffic sites. Node.JS with Socket.IO would be a good solution for you :)

0

精彩评论

暂无评论...
验证码 换一张
取 消