Home Web Front-end JS Tutorial jquery $.getJSON() cross-domain request_jquery

jquery $.getJSON() cross-domain request_jquery

May 16, 2016 pm 05:58 PM
cross domain request

1. The same domain name and other requests can be the same
js:

Copy code The code is as follows:

var url="http://localhost:2589/a.ashx";
$(function(){
$.getJSON(url,function(data){
alert (data.Name);
})
});

The server returns a string:
{"Name":"loogn","Age":23}
2,
js under different domain names:
Copy code The code is as follows:

var url="http://localhost:2589/a.ashx?callback=?";
$(function(){
$.getJSON(url,function(data){
alert (data .Name);
})
});

The server returns the string:
jQuery1706543070425920333_1324445763158({"Name":"loogn","Age":23})
The returned string is a function called "jQuery1706543070425920333_1324445763158", and the parameters are {"Name":"loogn","Age":23}.
In fact, this very long function name is the function of callback=? in the request path. I think it should be like this: The $.getJSON method generates a name that references the callback method, replace it? . The above request will become
http://localhost:2589/a.ashx?callback=jQuery1706543070425920333_1324445763158&_=1324445763194. The server needs to process it when returning json, such as:
Copy code The code is as follows:

string cb = context.Request["callback"];
context.Response.Write(cb "(" json ")");

The parameter name callback can also be replaced by jsoncallback. I think it is for fear of conflict. jsoncallback should be detected first, and callback should not be detected again (not tested!!)
? It can also be a specific function name, so the callback function cannot be anonymous. Use? Generation is just a convenience provided by jQuery for our general operations.
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use the Hyperf framework for cross-domain request processing How to use the Hyperf framework for cross-domain request processing Oct 20, 2023 pm 01:09 PM

How to use the Hyperf framework for cross-domain request processing Introduction: In modern network application development, cross-domain requests have become a common requirement. In order to ensure the separation of front-end and back-end development and improve user experience, it has become particularly important to use the Hyperf framework for cross-domain request processing. This article will introduce how to use the Hyperf framework for cross-domain request processing and provide specific code examples. 1. What is a cross-domain request? Cross-domain requests refer to JavaScript running on the browser through XMLHttpReques.

How to handle cross-domain requests and security issues in C# development How to handle cross-domain requests and security issues in C# development Oct 08, 2023 pm 09:21 PM

How to handle cross-domain requests and security issues in C# development. In modern network application development, cross-domain requests and security issues are challenges that developers often face. In order to provide better user experience and functionality, applications often need to interact with other domains or servers. However, the browser's same-origin policy causes these cross-domain requests to be blocked, so some measures need to be taken to handle cross-domain requests. At the same time, in order to ensure data security, developers also need to consider some security issues. This article will discuss how to handle cross-domain requests in C# development

Comparative analysis of PHP Session cross-domain and cross-site request forgery Comparative analysis of PHP Session cross-domain and cross-site request forgery Oct 12, 2023 pm 12:58 PM

Comparative analysis of PHPSession cross-domain and cross-site request forgery With the development of the Internet, the security of web applications has become particularly important. PHPSession is a commonly used authentication and session tracking mechanism when developing web applications, while cross-domain requests and cross-site request forgery (CSRF) are two major security threats. In order to protect the security of user data and applications, developers need to understand the difference between Session cross-domain and CSRF, and adopt

How to deal with cross-domain request issues in PHP development How to deal with cross-domain request issues in PHP development Jun 29, 2023 am 08:31 AM

How to deal with cross-domain request issues in PHP development In web development, cross-domain requests are a common problem. When the Javascript code in a web page initiates an HTTP request to access resources under different domain names, a cross-domain request occurs. Cross-domain requests are restricted by the browser's Same-Origin Policy, so in PHP development, we need to take some measures to deal with cross-domain request issues. Using a proxy server to forward requests is a common way to handle cross-domain

How to handle cross-domain requests in Vue projects How to handle cross-domain requests in Vue projects Oct 15, 2023 am 09:13 AM

How to handle cross-domain requests in the Vue project requires specific code examples. With the rapid development of front-end development, cross-domain requests have become a common problem. Due to the browser's same origin policy restrictions, when we need to send requests to different domain names or ports in the Vue project, we will encounter cross-domain problems. This article will introduce how to handle cross-domain requests in the Vue project and provide specific code examples. 1. Back-end settings CORS (cross-domain resource sharing) On the back-end server, we can set CORS to allow cross-domain resource sharing.

How to use php functions to optimize cross-domain requests and security restrictions? How to use php functions to optimize cross-domain requests and security restrictions? Oct 05, 2023 pm 12:34 PM

How to use PHP functions to optimize cross-domain requests and security restrictions? In web development, cross-domain requests and security restrictions are common problems. Cross-domain request refers to a page under one domain name accessing resources under another domain name. Due to browser security policies, ordinary cross-domain requests are prohibited. Security restrictions refer to measures to prevent malicious attacks and protect user privacy. PHP provides some functions and methods to optimize these problems. This article will introduce how to use these functions to solve the problems of cross-domain requests and security restrictions. For cross-domain request issues

Cross-domain request processing in Go language framework Cross-domain request processing in Go language framework Jun 03, 2023 am 08:32 AM

In web development, cross-domain requests are a common requirement. If a website needs to obtain data from another domain or call an API interface, it needs to use cross-domain requests. However, in order to ensure the security of the website, the browser will block such requests, causing cross-domain requests to fail. In order to solve this problem, we need to use some technical means to handle cross-domain requests. In this article, we will introduce the cross-domain request processing method in the Go language framework. What is a cross-domain request? In web development, front-end pages under the same domain name can

React cross-domain request solution: how to deal with cross-domain access issues in front-end applications React cross-domain request solution: how to deal with cross-domain access issues in front-end applications Sep 26, 2023 pm 02:48 PM

React cross-domain request solution: How to deal with cross-domain access issues in front-end applications, specific code examples are needed. In front-end development, we often encounter cross-domain request issues. Cross-domain request means that the target address (domain name, port, protocol) of the HTTP request sent by the front-end application is inconsistent with the address of the current page. Due to the browser's same-origin policy, cross-domain requests are restricted. However, in real development, we often need to communicate with different servers, so the solution for cross-domain requests is particularly important. This article will introduce Re

See all articles