Home Web Front-end JS Tutorial Solve the problem that WeChat returns to the previous page and the AJAX request in the page is invalid for the Get request

Solve the problem that WeChat returns to the previous page and the AJAX request in the page is invalid for the Get request

May 23, 2018 am 10:07 AM
page

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();
}
Copy after login

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 {
//方法体;
}
Copy after login

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=$(&#39;#isProfesser&#39;).val();
  var isreview=$(&#39;#isreview&#39;).val();
  var userid=$(&#39;#myId&#39;).val();
  if(isProfesser==&#39;0&#39; && isreview==&#39;0&#39;){
   $.ajax({
     url:"/isAuthenticing",
     data: {userid:userid},     type: &#39;POST&#39;,     success: function (data, textStatus, jqXHR) {
      if(data.result==&#39;1&#39;){
        $(&#39;#approveadd a&#39;).html("+认证中")
      }
     },
     error: function () {
     }
   });
  }
  //getMyQusetionInfo();
}
Copy after login

The back-end code:

@RequestMapping(value = "/isAuthenticing", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> isAuthenticing(@RequestParam("userid") String userid,HttpServletRequest request) throws IOException {
//方法体
}
Copy after login

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!

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 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks 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 copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

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

How to customize and edit standby mode on iPhone: What's new in iOS 17 How to customize and edit standby mode on iPhone: What's new in iOS 17 Sep 21, 2023 pm 04:01 PM

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

How to quickly refresh a web page? How to quickly refresh a web page? Feb 18, 2024 pm 01:14 PM

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

How to Rearrange, Disable, and Delete iPhone Home Screen Pages How to Rearrange, Disable, and Delete iPhone Home Screen Pages Nov 29, 2023 am 08:22 AM

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

How to implement page jump in 3 seconds: PHP Programming Guide How to implement page jump in 3 seconds: PHP Programming Guide Mar 25, 2024 am 10:42 AM

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

How to deal with the problem that Laravel page cannot display CSS correctly How to deal with the problem that Laravel page cannot display CSS correctly Mar 10, 2024 am 11:33 AM

"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.

Use ThinkPHP6 to implement a beautiful 404 page Use ThinkPHP6 to implement a beautiful 404 page Jun 20, 2023 am 11:06 AM

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

Introduction to how to delete a page of content in Word Introduction to how to delete a page of content in Word Mar 26, 2024 am 10:06 AM

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

See all articles