在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:kevinyhong/ajax-mini-sprint开源软件地址:https://github.com/kevinyhong/ajax-mini-sprint开源编程语言:JavaScript 96.4%开源软件介绍:AJAX Calls and HTTP Requests - AJAX Mini-SprintOverviewThis mini-sprint is designed to build an understanding of how client-server communications via HTTP and Asynchronous Javascript and XML (AJAX) requests, and how we can use these concepts and tools to send and receive data to and from a specified server. HTTP Request vs AJAX RequestA protocol for applications to take action on data sources is the Hypertext Transfer Protocol (HTTP). From fetching HTML documents to creating/updating data stored on another machine in another application, a HTTP request is at the core of these processes. One example of a request that you might be familiar with is when your browser makes a request for the HTML document when you navigate to a web page. While your browser might be making requests for the HTML document, style sheets, and scripts that are specified in the initial document, what if you wanted to fetch data that might be useful for your application or that you might want to display to the user (say your account balance) without hard-coding that into the document? That's where AJAX comes in: an AJAX request allows your applications to make HTTP requests to interact with resources without reloading the page. AJAX is AsynchronousBecause it takes some time for the request to reach it's destination and the browser doesn't know how long it'll take to receive a response back with the document we want, this process of sending a HTTP request and handling the associated response is typically asynchronous to prevent any blocking behavior when making the request. Because you don't know exactly when the response will arrive, you need to specify a callback function to be executed when our application receives the response. You can specify multiple callback functions based on the type of response you receive - an example would be in the event that we don't receive a successful response to our request, we may want our application to behave differently (think about unsuccessfully logging into your email account due to a email/password typo). JQuery's Ajax MethodTaking jQuery's ajax method as a starting point to understand how we can make requests about data, let's look at an example request to fetch some JSON data about random foods. We'll make a request to the Random Data API that are stored in the sampleData.json that is being served using json-server (data obtained from the Random Data API):
If the request is successful, we should see some JSON data come back:
The example above shows a few of the key components required for our AJAX request to provide us with the data we want:
Getting StartedEnvironment Setup
Exercises
Advanced ContentjQuery's AJAX method is not the only way that we can make AJAX requests in the browser, there are several other tools that can also accomplish this same task:
Further ResourcesUnderstanding Javascript Callbacks (Video) jQuery's AJAX method (Docs) See the docs directory for additional information on URLs and common HTTP methods CollaboratorsKevin Ong Ajax Request Prompts and Testing Refactor Fredrick Lou ReadMe and Directions Editing Tom Chandler, Initial Ajax Request Prompts and Testing Collin Snyder, ReadMe Editing Matt Co, ReadMe and Directions Editing, General Refactoring |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论