jQuery page refresh of local all problem analysis

  • 2020-11-26 18:40:34
  • OfStack

The example of this paper is divided into two parts to introduce jquery refresh problem. Part 1 introduces local refresh of the page. Part 2 covered full page refresh
Page local refresh

jQuery encapsulates the Ajax operation. In jQuery, the $.ajax () method is the lowest level method, the second layer is the laod(), $.get () and $.post () methods, and the third layer is the $.getScript () and $.getJSON () methods.
The load() method is typically used to get static data files from the Web server. To pass 1 parameter to the page in the server, you can use the $.get () or the $.post () method $.ajax


load() Code 
// If no parameter is passed, then yes GET way 
$("#resText").load("test.php",function(){
//......
});

// If there is parameter passing, then is POST way 
$("#resText").load("test.php",{name:"xht555",age:"24"},function(){
//......
});

1. Differences between post and get:

get: Simple data can be sent in get mode (i.e. the browser attaches each form field element and its data to url in the format of URL parameter), but the size is limited to 1KB. Cached by the client's browser, not secure.

post: The viewer sends each form field element and its data to the Web server as the entity content of the HTTP message, rather than passing it as a parameter to the URL address.

Conclusion:

1. GET means small amount of data transfer, high processing efficiency and low security, which will be cached, while POST means otherwise.

2: AJAX messy code problem
Reasons for disorderly code:
1. The default character encoding of the data returned by xtmlhttp is utf-8. If the client page is gb2312 or other encoded data, scrambled codes will be generated
2. post method: The default character encoding of the submitted data is ES54en-8. If the server side is gb2312 or other encoded data, scrambled code will be generated

The solutions are:
1. If the client is gb2312 encoding, then specify the output stream encoding on the server

2. utf-8 encoding is used for both the server and the client

gb2312:header('Content-Type:text/html;charset=GB2312');

utf8:header('Content-Type:text/html;charset=utf-8');

Note: If you have followed the above method and still return a garbled code, check that your method is get. For get requests (or those involving url pass parameters), the passed parameters are processed by encodeURIComponent first. If the encodeURIComponent processing is not used, it will also generate messy code


$.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) // Back function 
   {
    var myjson='';
    eval('myjson=' + data + ';');
    $('#result').html(" The name :" + myjson.username + "<br/> work :" + 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) // Back function 
   {
    var myjson='';
    eval("myjson=" + data + ";");
     $('#result').html(" The name :" + myjson.username + "<br/> work :" + myjson['job']);
   }
  );
});


});

$.getJson( " Default.php " , {id: " 1 " , page:  " 2 "  },
function(data){
// Notice, what's returned here JSON Data format, different from xml.
});


Page 2: Refresh all pages

1 window. location. reload() refreshes the current page.
2 parent. location. reload() Refresh the parent object (for frames)
3 opener.location.reload () refresh parent window object (for single-window opening)
4 top. location. reload() refreshes topmost object (for multiple Windows)

Above is the detailed content of this article, hope to be helpful to your study.


Related articles: