Home > Web Front-end > JS Tutorial > JS this scope and solution to the problem of too long GET transmission value_javascript skills

JS this scope and solution to the problem of too long GET transmission value_javascript skills

WBOY
Release: 2016-05-16 17:26:26
Original
1197 people have browsed it

When developing the project, the front end encountered two relatively hidden problems.

Problem 1. Specially for IE7 browser, the IE URL parameter is too long, causing HTTP Status 122 error
Reason: There is no problem under IE6.8, but it is not compatible with IE7. The get parameter is too long. , Google said "Don't use the GET method in Ajax Apps, if you can void it, because IE7 craps out with more than 2032 characters in a get string"

Solution:
Put the original The project uses the jsonp get data method and changes it to the regular post data method

Problem 2. This scope problem
Reason: If this is not inside the object, it defaults to the large object window, as shown below. Putting it inside an ajax refers to the current domain name ajax object

Solution:

Copy the code The code is as follows :

var test={};
test.getflash = 2;
test.test =function(){
alert(this.getflash); //2
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert(this.getflash); //Equal to undefine
}
});
}

Solution:
Copy code The code is as follows:

test.test =function(){
var thisValue = this;
alert(thisValue .getflash); //2
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert(thisValue.getflash); //2
}
});
}
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template