How to fix the failure of ajax on google chrome, ajaxchrome

Source: Internet
Author: User

How to fix the failure of ajax on google chrome, ajaxchrome

Problem Analysis: My ajax code is running normally in IE browser, 360 IE core browser, and Firefox, but it is a headache in google chrome, the correct result is always not displayed.

My local development environment is as follows:

Google chrome 28.0.146920.m
Tomcat6.0

The server-side Spring MVC code is as follows:

Controller part:

@RequestMapping(value="/searchRecordBlackListByCardId.json")public String searchRecordBlackListByCardId(HttpServletRequest request,HttpServletResponse response,String cardId,ModelMap mm){response.setContentType("application/json;charset=UTF-8");PwCardSpeciallist pcs = blackListService.getRecordBlackListByCardId(cardId);mm.addAttribute("pwCardSpeciallist", pcs);return "jsonView";}

Xxx-Servlet.XML configuration section:

<bean id="jsonView" class="net.sf.json.spring.web.servlet.view.JsonView"/><bean id="beanNameResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver">   <property name="order" value="0" /> </bean><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"p:viewClass="org.springframework.web.servlet.view.JstlView" p:order="100"p:prefix="/WEB-INF/jsp/"p:suffix=".jsp" />

Front-end page:

<script type="text/javascript">$(document).ready(function(){$("#searchBlack").click(function(){$.get('${requestScope.basePath}searchRecordBlackListByCardId.json', {   cardId : encodeURI( '123456789' )   }, function (data, textStatus){  alert(data.pwCardSpeciallist.cardId);  },'json');return false;})});</script>

For the above problems, let's give three answers so that you can see why ....

First, when using localhost: 8080/cardDemo/searchRecordBlackList.html # address for access:

 

The second one uses 127.0.0.1: 8080: 8080/cardDemo/searchRecordBlackList.html # For access:

 

The third one is 192.168.1.100: 8080/cardDemo/searchRecordBlackList.html #

 

It turns out that google chrome is forbidden to access local ajax resources due to a security policy! This is still a bit pitfall. After all, the company I used to work in claims to be "only supports GOOGLE CHROME" on some projects ".

This story tells us .... in future debugging, try to use the local IP address to access the SERVER, instead of 127.0.0.1 or localhost, so that it will not take several hours like me to look for this error.

Related Article

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.