JQuery page refresh (local, all) problem analysis, jquery page refresh

Source: Internet
Author: User

JQuery page refresh (local, all) problem analysis, jquery page refresh

This article introduces jquery refresh in two parts. The first part introduces partial page refresh. The second part introduces all page refresh.
First:Partial page refresh

JQuery encapsulates Ajax operations. In jQuery, $. the ajax () method belongs to the underlying method, and the layer 2nd is laod (), $. get () and $. post () method, layer 3rd is $. getScript () and $. getJSON () method.
The load () method is usually used to obtain static data files from the Web server. to pass some parameters to the page on the server, you can use $. get () or $. post () method $. ajax Method

Load () Code // if no parameter is passed, the GET method $ ("# resText") is used "). load ("test. php ", function (){//......}); // If parameters are passed, the POST method $ ("# resText") is used "). load ("test. php ", {name:" xht555 ", age:" 24 "}, function (){//......});

The difference between post and get is as follows:

Get: You can use get to transmit simple data (that is, the browser attaches the form field elements and their data to the URL according to the url parameter format), but the size is generally limited to 1 kb; it is not safe to be cached by the client browser.

Post: the browser sends the form field elements and their data to the Web server as the entity content of the HTTP message, rather than as a URL parameter,

Summary:

1. The GET method delivers a small amount of data, high processing efficiency, low security, and will be cached, whereas the POST method does not.

Ii. AJAX garbled characters
Cause of garbled characters:
1. The default character encoding of data returned by xtmlhttp is UTF-8. If the client page is gb2312 or other encoding data, garbled characters are generated.
2. The default character encoding for data submitted by the post method is UTF-8. If the server side is gb2312 or other encoding data, garbled characters are generated.

Solutions:
1. If the client is gb2312 encoded, specify the output stream encoding on the server.

2. Both the server and client use UTF-8 encoding.

Gb2312: header ('content-Type: text/html; charset = GB2312 ');

Utf8: header ('content-Type: text/html; charset = UTF-8 ');

Note: If you have already followed the above method or returned garbled characters, check whether your method is get. For get requests (or any request involving url parameters ), the passed parameters must be processed by the encodeURIComponent method. if you do not use encodeURIComponent for processing, garbled characters are generated.

$. Post () Code // $. post () method: $ ('# test_post '). click (function () {$. post ('ajax _ json. php ', {username: $ (' # input1 '). val (), age: $ ('# input2 '). val (), sex: $ ('# input3 '). val (), job: $ ('# input4 '). val ()}, function (data) // return function {var myjson = ''; eval ('myjson = '+ data +'; '); Parameters ('{result'}.html (" Name: "+ myjson. username + "<br/> job:" + myjson ['job']) ;}); $. get () Code // $. get () method: $ ('# test_get '). click (function () {$. get ('ajax _ json. php', {username: $ ("# input1 "). val (), age: $ ("# input2 "). val (), sex: $ ("# input3 "). val (), job: $ ("# input4 "). val ()}, function (data) // return function {var myjson = ''; eval (" myjson = "+ data +"; "); Parameters ('{result'}.html (" Name: "+ myjson. username + "<br/> job:" + myjson ['job']) ;}); $. getJson ("Default. php ", {id:" 1 ", page:" 2 "}, function (data) {// note that the JSON data format returned here is different from xml .});

Second:Page refresh

  • 1 window. location. reload () refresh the current page.
  • 2 parent. location. reload () refresh the parent object (for frame)
  • 3 opener. location. reload () refresh the parent window object (used for single-open window)
  • 4 top. location. reload () refresh the top object (used to open multiple Windows)

The above is the detailed content of this article, hoping to help you learn.

Articles you may be interested in:
  • Based on Jquery, the Web browser of Ajax requests can move backward and the page refresh function becomes more effective.
  • Implementation Code of jquery page refreshing (partial and full page refreshing)
  • Switch Based on jquery tab (prevent page refreshing)
  • Remember the position of the scroll bar when refreshing the page. jquery code

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.