How to implement Ajax to send a request without success
This time I will show you how to implement Ajax to send requests but not enter success, and how to implement Ajax to send requests but not enter success. What are the precautions? The following is a practical case, let's take a look.
1. Situation description: ajax was sent successfully, the background also successfully responded to the request, and returned json data. You can also see the response json by monitoring the request through chrome The data, but does not enter the success method, instead goes to the error method
Front end:
$.ajax({ type : "get", data : {'dbId':node.dbId,'viewId':node.id,'date':new Date()}, url : "${ctp}/ViewOperate/ShowViewSql", dataType : "json", success : function(data){ console.log(data); layer.alert(data,{ skin: 'layui-layer-molv' }); } error : function(data){ layer.alert("进入了error方法",{ skin: 'layui-layer-molv' }); } });
After End:
@RequestMapping(value="/ShowViewSql",method=RequestMethod.GET) @ResponseBody public String showCreateViewSql(@RequestParam(value="dbId",required=false)Integer dbId, @RequestParam(value="viewId",required=false)Integer viewId) { return "abc"; }
Cause: When the json data returned by the background is a pure String type object, the front end After the dataTypeattribute is set to json, it will be considered that the json data format converted from the String object is not the standard json format, so the method corresponding to the error will be executed.
Solution: No need to change the backend, just set the dataType attribute in the front-end ajax request to text
$.ajax({ type : "get", data : {'dbId':node.dbId,'viewId':node.id,'date':new Date()}, url : "${ctp}/ViewOperate/ShowViewSql", dataType : "text", success : function(data){ console.log(data); layer.alert(data,{ skin: 'layui-layer-molv' }); } error : function(data){ layer.alert("进入了error方法",{ skin: 'layui-layer-molv' }); } });
Special cases: When the json number returned by the backend is similar to "1", "2", "22", "232123", "-1", "232123.44" digital characters When string , when the front-end dataType attribute is set to json, the success method can be entered normally. The reason is unknown.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:Using Ajax and forms to implement the functions required for registered users
Steps to implement WeChat web page authorized login using ajax (With code)
The above is the detailed content of How to implement Ajax to send a request without success. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

On Douyin, users can not only share their life details and talents, but also interact with other users. In this process, sometimes we need to send files to other users, such as pictures, videos, etc. So, how to send files to others on Douyin? 1. How to send files to others on Douyin? 1. Open Douyin and enter the chat interface where you want to send files. 2. Click the "+" sign in the chat interface and select "File". 3. In the file options, you can choose to send pictures, videos, audio and other files. After selecting the file you want to send, click "Send". 4. Wait for the other party to accept your file. Once the other party accepts it, the file will be transferred successfully. 2. How to delete files sent to others on Douyin? 1. Open Douyin and enter the text you sent.

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

How to let others know that you have arrived at your destination. Telling others that you have arrived at your destination safely is the most common way of "checking in" and it is easy to operate. Here are the steps to set up before you’re ready to embark on the next leg of your journey. Open a message and start a conversation with the person you want to send a check-in to. Click the plus (+) icon next to the message field. Click Check-in. Click Edit at the bottom of the prompt. Enter the destination you want to go to. Select "Done" in the upper right corner and send "Check-in." "When entering your destination, you can choose different modes of travel depending on your needs, whether that's by car, public transport or walking. Make sure you choose the device you're using correctly so your device can accurately estimate how long it will take to get to your destination. This allows you to better plan your trip and get you to your destination more conveniently.

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.
