Pregunta

i am using the following code to send request to the server

var url='getDNormalForm.action';
var inputStr="test";
    var simTyp="andOr";
var pars={inputStr:inputStr, simTyp=simTyp};
$.post(url,pars);

I have defined my action in struts.xml as follow:

        <action name="getDNormalForm" class="ClassNameAction" method="getDNormalForm">
            <result name="andOr">test.jsp</result>
        </action>

When I send the post, I can see in firebug the following:

POST http://localhost:8081/myProject/getDNormalForm.action 200 OK 23ms

and i see in the answer tab the content of the page test.jsp, which means that I send the post and receive the answer successfully.

My question is: How can I show the page test.jsp as current page?

¿Fue útil?

Solución

$.post(
  url,
  pars, 
  function(response){
    $("body").html(response);
  }, "html");

So the third parameter is the callback function, i.e. the function that is called when the post request finishes (it is asynchronous, meaning that it does not block the execution of the script in browser). jQuery calls that function and passes to it the response as the first argument. Note the 4th parameter - "html", which says what should be the format of the "response" variable (may be text, json, xml, html). Inside the function we just replace the content of the body with the received content.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top