CS185c
Chris Pollett
Apr 2, 2012
request = new XMLHttpRequest()
request.setRequestHeader("name", "value")
request.open(theHTTPmethod, theURL, theAsync flag) or request.open(theHTTPmethod, theURL, theAsync flag, username, password)
request.open("GET", "progress.php", true)
var self = this; /* remember scope of enclosing object */ request.onreadystatechange = function() { switch(request.readyState) { case 0:// handle uninitialized case case 1: // handle open but no send case case 2: // handle send but no response case case 3: // handle response is being downloaded case case 4: // handle response has completed being downloaded case } }
document.getElementById("myDivTag").innerHTML = request.responseText; /*not really a DOM standard but all browsers happy with */ //or we could do... myDiv = document.getElementById("myDivTag") if(myDiv.firstChild) { myDiv.removeChild(myDiv.firstChild); } myDiv.appendChild(document.createTextNode(request.responseText));
request.send(null);Note: send's argument can be used if using POST method to send the posted data
function downloadDelayed() { $.ajax({ url : "myscript.php", success : function (data) { $("#contentArea").html(data); } }); } setTimeout("downloadDelayed()", 1000);
GET /mychat HTTP/1.1 Host: server.example.com Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw== Sec-WebSocket-Protocol: chat Sec-WebSocket-Version: 13 Origin: http://example.com
HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk= Sec-WebSocket-Protocol: chat
Below are the basic WebSocket Javascript functions (websocket URI's are prefixed with ws: or wss: (secure)):
var webSocket = new WebSocket("ws://some.websocketplace.org"); // Associate listeners webSocket.onopen = function(evt) { alert("The connection was opened"); }; webSocket.onmessage = function(evt) { alert("Received message: " + evt.data); }; webSocket.onclose = function(evt) { alert("The connection was closed"); }; webSocket.onerror = function(evt) { alert("Ouch an error!"); }; webSocket.send("This is some WebSocket data!"); // Close WebSocket webSocket.close();
Which of the following is true?
package org.pollett; import android.app.*; import android.widget.*; import android.os.Bundle; public class ListViewTest extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, FOOD)); getListView().setTextFilterEnabled(true); } static final String[] FOOD= new String[] { "Pizza", "Apple", "Calzone", "Ma Po Do Fu", "Pho Bo", "Curry", "Coffee", "Catfish" }; }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="8dp" android:paddingRight="8dp"> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="200sp" android:background="#00FF00" android:layout_weight="1" android:drawSelectorOnTop="false"/> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#EEEEEE" > <Button android:id="@+id/mybutton" android:layout_width="100sp" android:layout_height="wrap_content" android:text="Button" android:layout_x="19px" android:layout_y="347px" /> </LinearLayout> </LinearLayout>
package org.pollett; import android.app.*; import android.content.DialogInterface; import android.view.View; import android.view.View.OnClickListener; import android.widget.*; import android.os.Bundle; public class ListViewTest extends ListActivity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { View button; super.onCreate(savedInstanceState); setContentView(R.layout.main); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, FOOD)); getListView().setTextFilterEnabled(true); button = this.findViewById(R.id.mybutton); button.setOnClickListener(this ); } protected void onListItemClick(ListView l, View v, int position, long id) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("List Item Clicked"); alertDialog.setMessage("You clicked list item " + position); alertDialog.setButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } public void onClick(View v) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Button Clicked"); alertDialog.setMessage("You clicked the button"); alertDialog.setButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } static final String[] FOOD= new String[] { "Pizza", "Apple", "Calzone", "Ma Po Do Fu", "Pho Bo", "Curry", "Coffee", "Catfish" }; }
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"> <TableRow> <TextView android:layout_column="1" android:text="Open..." android:padding="3dip" /> <TextView android:text="Ctrl-O" android:gravity="right" android:padding="3dip" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:text="Save..." android:padding="3dip" /> <TextView android:text="Ctrl-S" android:gravity="right" android:padding="3dip" /> </TableRow> <View android:layout_height="2dip" android:background="#FF909090" /> <TableRow> <TextView android:text="X" android:padding="3dip" /> <TextView android:text="Import..." android:padding="3dip" /> </TableRow> </TableLayout>