Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
jQuery Ajax request to Struts2 action class always returns 200 ok, but error event is fired

I am new to Struts2 and I'm going to send set of form data to struts action class.

This is my Ajax code in jsp

$.ajax({
    method: "POST",
    url: "getProjectPost",
    data: { "language" : langArr , "clientId": clientId, "projectName": projectName, "projectType": projectType},
    traditional: true,
    success:
        function()
        {
    	alert("Success");
        },
    error: 
	   function()
        {
    	 alert("Error");
        }
});

This is my struts.xml:

<package name="projectPost" namespace="/" extends="struts-default">
    <action name="getProjectPost" class="com.test.ProjectPostAction" method="execute">
        <result name="success" type="redirect">
        <param name="location">/webpages/Client/Success.jsp</param >
        </result>
        <result name="failure">./LandingPage.jsp</result>
        <result name="error">./error.jsp</result>
    </action>
</package>

Ajax request returns 200 OK, but always alert "Error". I referred many articles but still not get proper solution

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You are sending result redirect while doing ajax request. Ajax request won't redirect you to another location, it will stay on the same page when request was made.

Change

<result name="success" type="redirect">

to

<result name="success" type="dispatcher">

The dispatcher is default result type that will render JSP at the specified location and write response HTML to the out. This response could be easily loaded with jQuery to any div available on the same page.

about 4 years ago · Santiago Trujillo Relatório

0

Yes, it is possible that you get response 200 OK still error callback is executed in ajax request because response from requested url is empty.

So you have to check server side code why response is empty or contact to back-end developer for same.

For more calcification you can use below code.

$.ajax({
    method: "POST",
    url: "getProjectPost",
    data: { "language" : langArr , "clientId": clientId, "projectName": projectName, "projectType": projectType},
    success: function(data){
        console.log("in success function");
        alert("Error:: " + data);
    },
    error: function(data){
         console.log("in error function");
         alert("Error :: "+ data);
    }
});
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda