


Solve the problem that WeChat returns to the previous page and the AJAX request in the page is invalid for the Get request
This article introduces WeChat to return to the previous page, the AJAX request in the page, the analysis and solution of the problem of invalid Get request, friends in need can refer to it
Let me first analyze the cause of the problem
When I was working on a WeChat project recently, I encountered a very common situation. The demand is like this. When the user enters "My Personal Center", there will be a button to click to jump to fill in the certification information. After clicking this button, it will jump to the certification information filling page, fill in the information, and submit it successfully. When the user returns directly to the previous page. The authentication status needs to be changed to "Authenticating". At this time, you need to use an AJAX method to query the authentication status and modify the status display on the page.
At that time, the ajax method was not written according to the standard method. The default method was Get request. The front-end JS code is as follows:
window.onload = function(){ var isProfesser=$('#isProfesser').val(); var isreview=$('#isreview').val(); var userid=$('#myId').val(); if(isProfesser=='0' && isreview=='0'){ $.ajax({ url:"/isAuthenticing", data: {userid:userid}, success: function (data, textStatus, jqXHR) { if(data.result=='1'){ $('#approveadd a').html("+认证中") } }, error: function () { } }); } //getMyQusetionInfo(); }
Background controller The default received is also GET
@RequestMapping(value = "/isAuthenticing", method = RequestMethod.GET) @ResponseBody public Map<String, Object> isAuthenticing(@RequestParam("userid") String userid,HttpServletRequest request) throws IOException { //方法体; }
Solution
Practice has proved that using the Get method It doesn't work. Every time you go back to the previous page, the ajax method in the page will be executed as usual, but it will not request the background controller. The value returned by the request is also the value when the page was last loaded. I don't know the specific reason for the time being. clear.
Later, with the mentality of giving it a try, I used POST request. Surprisingly, using POST request, the whole process went smoothly.
The front-end JS code is as follows:
window.onload = function(){ var isProfesser=$('#isProfesser').val(); var isreview=$('#isreview').val(); var userid=$('#myId').val(); if(isProfesser=='0' && isreview=='0'){ $.ajax({ url:"/isAuthenticing", data: {userid:userid}, type: 'POST', success: function (data, textStatus, jqXHR) { if(data.result=='1'){ $('#approveadd a').html("+认证中") } }, error: function () { } }); } //getMyQusetionInfo(); }
The back-end code:
@RequestMapping(value = "/isAuthenticing", method = RequestMethod.POST) @ResponseBody public Map<String, Object> isAuthenticing(@RequestParam("userid") String userid,HttpServletRequest request) throws IOException { //方法体 }
Hope it can help those who encounter the same problem as me.
Note: The red part is the modified part
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
ajax uses json to realize data transmission
Ajax transfers JSON example code
The post method in Ajax directly returns a number starting with 0 and error analysis
##
The above is the detailed content of Solve the problem that WeChat returns to the previous page and the AJAX request in the page is invalid for the Get request. 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

AI Hentai Generator
Generate AI Hentai for free.

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



Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

Standby is a new feature in the iOS 17 update that provides a new and enhanced way to access information when your phone is idle quickly. With StandBy, you can conveniently check the time, view upcoming events, browse your calendar, get weather updates for your location, and more. Once activated, the iPhone will intuitively enter standby mode when set to landscape while charging. This feature is perfect for wireless charging points like your bedside table, or when you're away from your iPhone charging during daily tasks. It allows you to swipe through various widgets displayed in standby to access different sets of information from various applications. However, you may want to modify these widgets or even delete some based on your preferences and the information you need frequently. So let's dive into

Page refresh is very common in our daily network use. When we visit a web page, we sometimes encounter some problems, such as the web page not loading or displaying abnormally, etc. At this time, we usually choose to refresh the page to solve the problem, so how to refresh the page quickly? Let’s discuss the shortcut keys for page refresh. The page refresh shortcut key is a method to quickly refresh the current web page through keyboard operations. In different operating systems and browsers, the shortcut keys for page refresh may be different. Below we use the common W

In iOS, Apple allows you to disable individual home screen pages on your iPhone. It's also possible to rearrange the order of home screen pages and delete pages directly instead of just disabling them. Here's how it works. How to Rearrange Home Screen Pages Touch and hold Space on the Home screen to enter jitter mode. Tap the row of dots that represent Home screen pages. In the Home screen grid that appears, touch and drag a page to rearrange it relative to other pages. Others move in response to your dragging. When you're happy with your new arrangement, tap "Done" in the upper right corner of the screen, then tap "Done" again to exit dither mode. How to Disable or Remove Home Screen Pages Touch and hold Space on the Home screen to enter dither mode. Tap to represent home screen

Title: Implementation method of page jump in 3 seconds: PHP Programming Guide In web development, page jump is a common operation. Generally, we use meta tags in HTML or JavaScript methods to jump to pages. However, in some specific cases, we need to perform page jumps on the server side. This article will introduce how to use PHP programming to implement a function that automatically jumps to a specified page within 3 seconds, and will also give specific code examples. The basic principle of page jump using PHP. PHP is a kind of

"Methods to handle Laravel pages that cannot display CSS correctly, need specific code examples" When using the Laravel framework to develop web applications, sometimes you will encounter the problem that the page cannot display CSS styles correctly, which may cause the page to render abnormal styles. Affect user experience. This article will introduce some methods to deal with the failure of Laravel pages to display CSS correctly, and provide specific code examples to help developers solve this common problem. 1. Check the file path. First check the path of the CSS file.

As the Internet develops, many websites or applications have gradually become more complex. When users use it, they often encounter error pages, the most common of which is the 404 page. The 404 page means that the page being accessed does not exist and is a common error page. For websites or applications, a beautiful 404 page can greatly improve the user experience. In this article, we will introduce how to use ThinkPHP6 to quickly implement a beautiful 404 page. Create a route First, we need to create an err in the route folder

Title: Introduction to how to delete a page of content in Word When editing a document using Microsoft Word, you may sometimes encounter a situation where you need to delete the content of a certain page. You may want to delete a blank page or unnecessary content on a certain page in the document. In response to this situation, we can take some methods to quickly and effectively delete a page of content. Next, some methods to delete a page of content in Microsoft Word will be introduced. Method 1: Delete a page of content First, open the Word document that needs to be edited. Certainly
