When javascript-Thinkphp uses ajax, sometimes the relative address is used to report an error. why?

Source: Internet
Author: User
For example: {code...}. for example, in the above code, the url has obtained the relative address using the U method. If I directly use the url during post, the whole page will be returned. after the root is added, it can be used normally. Have you ever encountered a similar situation? And in some places:

var root=window.location.origin;$.post(root+"/"+url,data,function(d){    console.log(d);  if(d.status==1){    location.reload();  }})

For example, in the above code, the url has previously obtained the relative address using the U method.
If I use a url directly during post, the whole page will be returned,
After the root account is added, it can be used normally.

Have you ever encountered a similar situation?

This is only true in some places, but not in general.

This page uses the Baidu editor. what is the impact?

Note:
The above may not be clearly expressed. the request address after I add root is: root + "/" + url,
When not added, the request is: url (I did not add "/" in front of it "/").

The url address is obtained on this page using the Thinkphp U method. of course, it can be accessed directly and the correct address; so I will have such questions.

Reply content:

For example:

var root=window.location.origin;$.post(root+"/"+url,data,function(d){    console.log(d);  if(d.status==1){    location.reload();  }})

For example, in the above code, the url has previously obtained the relative address using the U method.
If I use a url directly during post, the whole page will be returned,
After the root account is added, it can be used normally.

Have you ever encountered a similar situation?

This is only true in some places, but not in general.

This page uses the Baidu editor. what is the impact?

Note:
The above may not be clearly expressed. the request address after I add root is: root + "/" + url,
When not added, the request is: url (I did not add "/" in front of it "/").

The url address is obtained on this page using the Thinkphp U method. of course, it can be accessed directly and the correct address; so I will have such questions.

The relative address is relative to the address bar of the current browser and has nothing to do with ThinkPHP.

/Is the root address. you can directly use/to indicate the access from the domain name +/+ url. if the root address is the root address, it will not be wrong, and the problem cannot be found;
If you use window. location. origin, it indicates that you use the relative address. the requested url is under the relative address window. location. origin;
You 'd better start your AJAX request path from the root directory and write the full path. This problem has nothing to do with tp, and your own understanding of the request address is incorrect.

base_urlGreat way.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.