PHP Comet push
Set_time_limit (0);Ob_start ();$pad = Str_repeat (' ', 4000);Echo $pad, '';Ob_flush ();Flush (); Send the resulting content to the browser immediately instead of waiting for the script to end.$i = 1;while ($i + +) { Echo $pad, ''; echo $i, ''; Ob_flush (); Flush (); Send the resulting content to the browser immediately instead of waiting for the script to end. Sleep (1);}
This code is copied online, the code is not a
status of the response
Description of the Statustext:http status
Regardless of the content type, the contents of the response body are saved to the responseText property, and for 非XML数据 that matter, the value of the Responsexml property will be null .When a response is received, in general, the status is judged to be 200, which is a sign of the success of this request. At this point, the responseText contents of the property are ready and can be accessed if the content type is correct
, Ajax synchronous submission is valuable? This is not as good as using a form to do synchronous submission, this to specific problems, I mentioned in the previous traditional synchronous submission of HTTP precision control is very poor, if some synchronization request we need more HTTP control then use AJAX better, in addition to the traditional synchronous request response is to overwrite the original page, It is either a new form to receive the response, but the synchronous Ajax is more flex
Comet Discovery Series two "Ajax polling multiplexing Model"write in front: Ajax polling believe that everyone is using, but there is such a problem, if a site at the same time there are a lot of places need to use this poll? Take our website, there is an unread message number reminder, there is a time to load the latest said, yesterday added a full network, and later will have a similar function to add is sure, do you want to create a separate pollin
Comet (Reverse AJAX) is mainly used to maintain a connection with the Server through HTTP persistent connections to implement Server PUSH and bidirectional communication. The following uses an example to learn how to use it.Benefits: 1. Resource Saving and low latency compared with AJAX polling. 2. Compared with webSocket, it is widely used. 1. first, create an empty Asp.net MVC project to add a Controller (the same code can also be used in Asp.net We
cached clients. clear (); // clear the list object after broadcasting}. This completes the first operation. when you enter text in the broadcast and click to send it: the process still passes the web. confing to the asnyhandler class, execute beginpro Cessrequest method. instantiate Class Object: myasynresult receives the string content object through the content that jquery will broadcast. the above is the same as the first run until the addmessage method enters the else send method details: P
Ajax and Comet
Ajax (short for Asynchronous JavaScript + XML)You can request data from the server without detaching (refresh) the page to bring a better user experience.
The core of Ajax technology is the XMLHttpRequest object (XHR ).I. XMLHttpRequest object
/* Compatible with earlier IE versions */function createXHR () {if (typeof XMLHttpRequest! = "Undefined") {return new XMLHttpRequest ();} else if (typeof ActiveXObject! = "Undefined") {// applica
Comet ("Server Push" technology based on HTTP long connections)The Web server sends the data passively to the client, the client requests it, the server responds (sends the data),So the "server push" technique adds quotes.There are two ways to achieve this:1. Ajax-based long polling (long-polling) modeThe browser sends an AJAX request (sets a timeout and processes the returned state,Conjecture: Setting the timeout,connection:keep-alive will be added t
1.prepare front-end code, Meta Content-type cannot be ignored! As to the XHR, status should be 32.back-end, remember to-call, both methods to set time limit to unlimited and cache-control to be no-cache;Comet realization with ajaxphp
were at IP address" + Response.ip + ", which was in" +3Response.city + "," + response.region_name);//try to really can pop up my address!!! 4 }5 6 varScript = document.createelement ("Script"); 7SCRIPT.SRC = "Http://freegeoip.net/json/?callback=handleResponse"; Specifies that the callback function is Handleresponse ()8Document.body.insertBefore (Script,document.body.firstchild);Compared to the picture ping, the advantages of JSONP are:1) Direct access to response text2) supports two-way
When we want to display some data in the browser in real time, how? There are many ways to implement, the simplest is to set an interval, Ajax constantly send requests, this way the most obvious flaw whether or not new data will always send the request, and this interval if set long, timeliness is too poor, If the interval is set short, each client is constantly sending a large number of requests that affect server performance Another is the use of server push technology, based on the way of l
= 1000; Xhr.ontimeout=function() {}xhr.send (NULL) Two: Using the XMLHttpRequest EventProgress Event: The following 6 progress events are available. Loadstart,progress, error, Abort, load, loadend.1) Use Load event optimization:var xhr newfunction() { try{ if ((xhr.statue>=200 xhr.status) {xhr.responsetext}} catch(ex) {// Suppose there is a ontimeout processing event} =thefunction() {}xhr.send (null )Whenever the browser receives a server response, the load event
The iOS Simulator is a helper tool that can be used when developing a program on the iOS platform under Mac. iOS Simulator is part of the Xcode, Xcode is Apple's own iOS development program that can be downloaded for free!
The IOS Simulator is located in the/developer/platforms/iphonesimulator.platform/developer/applications folder. Typically, you do not need to
The core of Ajax technology is the XMLHttpRequest object (referred to as XHR), which is the first feature that Microsoft introduced, before the advent of XHR, Ajax communication must be implemented with some hack means, most of them using a hidden framework embedded framework. XHR provides a smooth interface for sending requests to the server and for the server's response. XHR can get more information asynchronously from the server, meaning that users can get new data without refreshing the page
1.Ajax core?Xhr>>1. New XMLHttpRequest>>2.open (), accepts 3 parameters.>>3.send (), accepts 1 parameters.>>4. When a server response is received, the response data is automatically populated with the properties of the Xhr object.ResponseTextResponsexmlStatusStatusText>> Sync requests, receive responses, check the following in order: status attribute; responsetext;responsexml;>> asynchronous request, receive response, check the following: Readystatus2.HTTP Header InformationSetrequeseheader ();
Comet: server Push , as opposed to the AJAX page requesting data from the server. Data can be pushed to clients almost instantly.But essentially the same: the browser initiates a request to the server, and the server responds to the requestComet implementations: Long polling, HTTP streaming1. Long polling-all browsers supportThe browser sends a request to the server and responds if there is valid data on the server side, otherwise "ignores".Once the s
The method is as follows:
1, first of all, we want to download bit comet software. After the download is complete, double-click the program file installation, the program is not large, more than 10 MB. Install the first step, select the program language, the default is Chinese.
2, then is the software of the specific installation process, is the next step, very simple, no longer repeat.
3. When the software insta
comet (Reverse AJAX) is primarily connected through an HTTP long connection, maintaining a connection to the server, implementing server PUSH and two-way communication, and following the example to learn how to use it Benefits: 1. Save resources compared to Ajax polling, and latency is small, 2. Compared with websocket, the applicable scenarios are quite extensive. nbsp; 1. First create an empty project for asp.net MVC nbsp; Add a controller nbsp; (
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.