In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "what are the common problems of ajax objects?". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1) the properties of standard ajax objects are readyState,status,responseText,responseXML
2) non-standard ajax object properties, for IE browsers, there are responseBody,2 binary data streams. If browser compatibility is not taken into account, this attribute + VBScript can solve the garbled problem very well.
Visual Basic code
1.
2. Function Bytes2BStr (vin) 'binary conversion string
3. Strreturn = ""
4. For I = 1 to lenb (vin)
5. Thischarcode = ascb (midb (vin,i,1))
6. If thischarcode < & h80 then
7. Strreturn = strreturn & chr (thischarcode)
8. Else
9. Nextcharcode = ascb (midb (vin,i+1,1)
10. Strreturn = strreturn & chr (clng (thischarcode) * & h200 + cint (nextcharcode))
11. I = I + 1
12. End if
13. Next
14. Bytes2BStr = strreturn
15. End Function
3) event onreadystatechange, state transition function
4) the method has setRequestHeader,open,send, which is used to set the response header. When you specify the submission method as POST, you need to set content-type to application/x-www-form-urlencoded. If this response header is not set, the requested dynamic page cannot get the value in the form of key-value pairs, but the submitted data can be generated from the binary stream.
Referenc
How to get submitted content when ajax is specified as post but content-type is not set or key is not specified
Problems that are prone to mistakes
1) for objects created using XMLHttpRequest, including the IE7+, attribute is strictly case-sensitive, be sure to pay attention to the case problem, or not case-sensitive, the attribute value is undefined. For example, readyState is written as readystate,responseText and written as responsetext.
2) for IE browsers, if activexobject is judged first, activexobject will be executed to create xhr objects, and xhr objects, properties, events, and methods created by acx are not case-sensitive.
3) when creating with XMLHttpRequest, the onreadystatechange must be all lowercase, or it is equivalent to assigning a custom property to the xhr object, rather than the actual state transition function. This will never perform a callback. Case-insensitive xhr objects created by IE using activexobject
4) same as 2: 00 or 3: 00, when XMLHttpRequest is created, the calling method must be case-sensitive, or it will make an error and prompt that the method cannot be found. IE creation using activexobject is not case-sensitive.
In particular, the open method must be called before the setRequestHeader method can be executed, or there will be an error.
Some suggestions for handwritten ajax code
1) when submitting for get, there is no need to set content-type, unless the request is some file that needs to check content-type to generate some corresponding data format. For example, the webservice of asp.net will check the content-type. If you specify content-type as application/json, the corresponding string in json format will be generated.
2) when submitting for get, if there is no data, it is best to add a null as a parameter when calling the send method. Xhr.send (null)
3) when submitting for post, don't forget to call the open method and then call the setRequestHeader method to set content-type to application/x-www-form-urlencoded.
4) when using the responseText,responseXML and ResponseBoy [IE only], status attribute, you need to use it when readyState==4,status status = = 200 [online test] or status status = = 0 [local test]
JavaScript code
1.
2. Var xhr = window.XMLHttpRequest? New XMLHttpRequest (): new ActiveXObject ("microsft.xmlhttp")
3. Xhr.open ('get',' index.html', true)
4. Xhr.onreadystatechange = function () {
5. If (4 = = xhr.readyState) {
6. If (200 = = xhr.status | | 0 = = xhr.status) {
7. / / = processing code after normal return
8.}
9. Else alert ('there is something wrong with the dynamic page ~')
10.}
11.}
12. Xhr.send (null)
5) if it is executed asynchronously, you need to add a state transition function, and then use the responseText or responseXML attribute when readyState bit 4.
If you are synchronizing, you can use the responseText or responseXML property directly after the send, without adding the onreadystatechange state transition function. However, if the network speed is slow during synchronization, it is easy to fake the death of the browser and the user experience is not good.
6) switch to the jquery framework for the simplest hoho~~.
This is the end of the content of "what are the common problems with ajax objects?" Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.