javascript - ajax refresh problem

WBOY
Release: 2016-10-10 11:56:09
Original
1002 people have browsed it

I just want an effect similar to segmentfaul. Click on which partition to display the corresponding content. But the problem now is that I don’t know how to write the href link. I want the content to be displayed on the current page. Herf cannot be written #. If I writehref="1. html"will display the data first and then jump. In this case, the page will be empty and the data cannot be displayed. What should we do? Please look carefully. I don't want to prevent the jump. I want to know how the effect of segmentfault is achieved. If you use ajax, there is no need to jump to refresh the page. But segmentfault has a jump refresh. How is this achieved?

代码只是大概描述一下 1.html      
  java php 
Copy after login
Copy after login

Reply content:

I just want an effect similar to segmentfaul. Click on which partition to display the corresponding content. But the problem now is that I don’t know how to write the href link. I want the content to be displayed on the current page. Herf cannot be written #. If I writehref="1. html"will display the data first and then jump. In this case, the page will be empty and the data cannot be displayed. What should we do? Please look carefully. I don't want to prevent the jump. I want to know how the effect of segmentfault is achieved. If you use ajax, there is no need to jump to refresh the page. But segmentfault has a jump refresh. How is this achieved?

代码只是大概描述一下 1.html      
  java php 
Copy after login
Copy after login

Just write a separate url, it is either ajax refresh or get. There are many small sections that are actually not a big problem, and the backend is also very easy. Because the data formats are basically the same, just write a regular expression to match the requested URL when matching routes, then process the data in a controller, and return different data according to different URLs. Moreover, the front-end template does not need to change greatly and is highly reusable.

In the event handler function, you can prevent the browser's default behavior (the default behavior here is to jump) by callingpreventDefaultorreturn false. In addition, it is server rendering, not ajax.

Finally, it is recommended to buy this book and study systematically. These questions are really too basic. Even if you have not studied systematically, searching or checking the API is much more efficient than asking questions

No matter what thehrefofis, you can prevent the default behavior in the event

The following is the jQuery code, the native code is almost the same, call preventDefault() of event, or returnfalse.

$("#java").on("click", e => { e.preventDefault(); });
Copy after login

But you can also directly sethrefso that it does nothing

...
Copy after login

When you click on a page, the js code corresponding to this page sends an HTTP GET request to the background, and then the background returns the corresponding (such as java/php, etc.) data.

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!