html form submission type

When you make a POST request, you have to encode the data that forms the body of the request in some way.

HTML forms provide three methods of encoding.

  • application/x-www-form-urlencoded (the default)
  • multipart/form-data
  • text/plain

Work is being done on adding application/json.

The specifics of the formats don’t matter to most developers. The important points are:

When you are writing client-side code, all you need to know is use multipart/form-data when your form includes any <input type="file"> elements.

When you are writing server-side code: Use a prewritten form handling library (e.g. Perl’s CGI->param or the one exposed by PHP’s $_POST superglobal) and it will take care of the differences for you. Don’t bother trying to parse the raw input received by the server.

Never use text/plain.


If you are writing (or debugging) a library for parsing or generating the raw data, then you need to start worrying about the format. You might also want to know about it for interest’s sake.

application/x-www-form-urlencoded is more or less the same as a query string on the end of the URL.

multipart/form-data is significantly more complicated but it allows entire files to be included in the data. An example of the result can be found in the HTML 4 specification.

text/plain is introduced by HTML and is useful only for debugging — from the spec: They are not reliably interpretable by computer — and I’d argue that the others combined with tools (like the Net tab in the developer tools of most browsers) are better for that).

Advertisements

google spreadsheet api json xml html

It is not that straight forward to get the xml/json/html outpt for  a google spreadsheet. 

 

HTML

First thing we need to do is to publish the sheet under File -> publish to the web….

Here is what you may get
https://docs.google.com/spreadsheets/d/YOUR-SHEET_ID/pubhtml

Now you have the html version. 

XML/JSON 

After you get the shee-id, what you need to do is to find the grid id of the sheet use: 

https://spreadsheets.google.com/feeds/worksheets/YOUR-SHEET_ID/public/basic

After open the above URL, we get a summary of the published sheet. Then we can find the grid id under the entry element:

<id>https://spreadsheets.google.com/feeds/worksheets/YOUR-SHEET_ID/public/basic/GRID-ID</id>

Now using the combination of  GRID-ID and YOUR-SHEET_ID, we should be able to get the xml/json output by:

XML —->   http://spreadsheets.google.com/feeds/list/YOUR-SHEET_ID/GRID-ID/public/values

JOSN —->  http://spreadsheets.google.com/feeds/list/YOUR-SHEET_ID/GRID-ID/public/values?alt=json-in-script

回车按键自定义事件

ajax聊天界面中,由于是镶嵌在游戏界面中,有很多按钮,于是看了下如何让enter键直接指定在send按钮上

  方法是:在body tag那里加上keyCode是否13的判断。
   body onkeyup=”if(event.keyCode==13){sendMessage();}”

clear:both的理解

<div style=”border:2px solid red;“>

    <div style=”float:left;width:80px;height:80px;border:1px solid blue;“>TEST DIVdiv>

    <div style=”clear:both;“>div>

div>

 

将此部分代码放到一个HTML页面看效果,然后在去掉<div style=”clear:both;“>div>看一下效果

 

如图:

 

1)有clear:both的:

你真的理解clear:both吗?

 

2)无clear:both

你真的理解clear:both吗?

 

这样看,应该就一目了然了:原来后边的Clear:both;其实就是利用清

除浮动来把外层的div撑开,所以有时候,我们在将内部div都设置成浮动之后,就会发现,外层div的背景没有显示,原因就是外层的div没有撑开,太小,所以能看到的背景仅限于一条线。