0

I am trying to hit PaymentController.java via ajax request it is giving me the error shown in attached screenshot. I have tried alot but not able to hit the controller. My motto is to hit the controller and get the returning string. The error that bothering me is: Being novice in Spring-MVC I am unable to understand the real cause of this error.

Failed to load http://localhost:8088/paymentgateway/payment/2100002:

{
  "readyState": 0,
  "status": 0,
  "statusText": "NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://localhost:8088/paymentgateway/payment/2100002'."
}

enter image description here

My Project Structure is as follows:

enter image description here

MyAjaxRequest is as follows:

<script type="text/javascript">
    function test(){
    var testData =  {}
//  var testData =  {"orderID":"2100002"}
        var URL= "http://localhost:8088/paymentgateway/payment/2100002"
            $.ajax({
                url : URL,
                async :false,
                type : 'POST',              
                dataType : 'json',
                data: JSON.stringify(testData),
                contentType : 'application/json',
                mimeType : 'application/json',
                crossDomain : true,
                success : function(data) {  
                console.log(JSON.stringify(data,null,4));
                alert(data);
                },
                error : function(data, status, er) {
                console.log(JSON.stringify(data,null,4));
                    console.log("Errors : "); 
                }
            });
            }
    </script>

PaymentController.java

@Controller
@RequestMapping(value = "/paymentgateway")
public class PaymentController {

    @RequestMapping(value = "/payment/{orderID}", method = RequestMethod.POST)
    public String paymentGateway(Model model, @PathVariable String orderID)
            throws Exception {
        System.out.println("inside controller");

        String str="Payment Done";
        return "Hello";

    }

}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>HelloPayment</display-name>
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/appServlet-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/appServlet-servlet.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

appServlet-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
        http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd">

    <context:component-scan base-package="com.majesco.*" />
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

</beans:beans>

Request status:

enter image description here

nirmal sharma
  • 73
  • 1
  • 10

1 Answers1

1

Please show me request status. Chrome: F12 -> network -> and choose request there. It looks like security issue, please, provide your security config, and disable cors(). Or try to set cross domain as 'false'.

lord_hokage
  • 189
  • 7