This is often the case when implementing data interaction with the background:
1. Need to use an AJAX request background data, and to get the data and then render to the page, this time must be synchronized (Async:false).
2. However, there will be
Using XMLHttpRequest to send AJAX requests
1. Create an object:
function Createxmlhttp () {
var xmlHttp;
try{
xmlhttp= new XMLHttpRequest ();
}catch (e) {
try{
Ie
xmlhttp= new ActiveXObject ("Msxml2.xmlhttp");
}catch (e) {
try{
Ie
xmlhttp= new
Let's look at a piece of code like this:
$ (function () {
var a =0;
$.getjson (
"Student_toadd",
{Stunum:10},
function (Json,status){$.each (Json,function (i) {$ (' #stuDiv '). Append (" Student study Number:" +json[i].num+ "");}
....................
Error Tip:No ' Access-control-allow-origin ' header is present on the requested resource.
cause of the errorJavaScript is in security consideration and is not allowed to be accessed across domains.
Solutions 1. Install pip install
First, the native JS implementation:
var request = new XMLHttpRequest (); Create a XMLHttpRequest () object
Initiates an HTTP request, but does not send the request to the server, and the last parameter defaults to False, which is sent
$.ajax ({
URL: "Http://www.xxx",//requested URL address
dataType: "JSON",//The format returned is JSON
async:true,//request is asynchronous, default true is asynchronous , this is an AJAX feature
data:{"id": "value"},//parameter
The restrictions on cross-domain communication are on the browser side, which is the client, so you can make a fuss from server-side code. This is the same as the last few days gzip, the problem is very similar to the gzip stream on the server
This is the ajax.html for displaying the subject.
"Http://www.w3.org/TR/html4/strict.dtd" >
ajax Web Development Example
ajax Web Development Example
take a look at the example below and you'll probably understand how the data is done
The following is a personal understanding, please correct me in the wrong place.
Ajax basic use is mainly used to implement the Web page and the server asynchronous interaction, so that users do not feel or do not wait for the page to refresh.
The
The Ajax submit form allows you to serialize the form form and then submit the data to the background, such as:
$.ajax ({url: "http://localhost:8080/", type: "POST", Data: $ (' #postForm '). Serialize (), Su Ccess:function (data) {}, Error:function
The div tag is used to generate a DIV element on the page, but the DIV element content is not static content but gets the data from the server, so that the div can get the data on the server, you must specify an href attribute for the div tag, this
Uploading files via a traditional form form submission: HTML code test upload files via rest interface Specify filename: uploading file: keyword 1: keyword 2: keyword 3:
AJAX is an acronym for Asynchronous JavaScript and XML. Essentially, a piece of JavaScript can create an HTTP request and directly update a part of the page without a post or get request like normal, and refresh the entire page. Even better, a page
Recently in doing a project, because it involves cross-platform, so the use of jquerymobile this framework, in the development process, the first for the purpose of testing, using a Chrome browser to test the run. The following questions are
Please enter http://blog.csdn.net/hzz780/article/details/42124607 using PHP
In other words, last week, the page local JSON data debugging handed to the program, he told me to always return the error, not executed. I went to the interview with my
first the code.
function SubmitData () {
var xhr = createxhr (); Creates a Xhr object.
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {//ensures that all response data has been obtained
if ((Xhr.status >= 200&&xhr.status
alert
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