douhezhan5348
douhezhan5348
2014-06-01 21:36
浏览 28

具有名称属性的元素转到服务器:仅限PHP约定?

Many places have said that only elements with a name attribute go to the server on page change, and only the element name and its value attribute's value travel between client & server. Is this a PHP feature or is it also present in other scripting languages? For example, is this the case with Node.js, or any of its popular server frameworks like express or grunt? Also, are there ways to send other elements or attributes to the server?

I know that AJAX can cause pretty much anything to go to the server, but this is usually asynchronous, and even when it isn't the info doesn't usually go to the server right when the page is sent. If you have any relevant info on AJAX, though, please share it.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufu5521
    doufu5521 2014-06-01 22:04
    已采纳

    When you give an element a name attribute, the browser will send the form data in the body of the request (if using POST) or in the query string (if using GET). This happens no matter what language or framework you use.

    name is the only attribute that does this - it will not work with an id - but you can also do this with AJAX, by passing a querystring to XMLHttpRequest.send (if you're using jQuery, read up on jQuery.post). Requests via AJAX are, to the server, identical to requests from the client. If you send data in an AJAX POST request, it will be identical to a request via an equivalent form to the server. This is the same whether you're using PHP, Node.js, or any other web framework.

    Helpful references:

    点赞 评论

相关推荐