ajax - Struts2 url not hitting correct action -


I have written an Ajax call to call struts2 action, but to define its method by default, but defined There is no method for struts.xml. Please tell me how to create the URL in JavaScript to call the correct action with the method defined in struts.xml

code:

  function showCustomer (str) { EmailRequest = create request (); If (emailRequest == faucet) {Warning ("Unable to make a request"); } Else {var emailValue = document.getElementById ("Email"). Values; Var Email = Escape (Email Value); Warning (email) var url = "Recover Password; Recovery Password? Email =" + Email; Alert (URL) Email request. EmailRequest.open ("post", url, true); EmailRequest.send (zero); }} Function showemailStatus () {if (emailRequest.readystate == 4) {if (emailRequest.status == 200) {if (emailRequest.responseText.match ("EamilIdExists")) {document.getElementById ("show") style .display = 'block'; } And {document.getElementById ("email"). Focus (); Warning ("email id does not exist"); Return; }}}}  

struts.xml:

  & lt; Action Name = "Recover Password" category = "com.astro.action.CheckEmailAction" method = "recoverPassword" & gt; & Lt; Result type = "stream" name = "success" & gt; & Lt; Param name = "content type" & gt; Text / html & lt; / Param & gt; & Lt; Param name = "input name" & gt; Inputstream & lt; / Param & gt; & Lt; / Results & gt; & Lt; Result type = "stream" name = "input" & gt; & Lt; Param name = "content type" & gt; Text / html & lt; / Param & gt; & Lt; Param name = "input name" & gt; Inputstream & lt; / Param & gt; & Lt; / Results & gt; & Lt; / Action & gt;  
  1. Rename action: declared the same action class Many times with multiple names, (and without) with different methods and when you change the name, you can call bang ! If you do not have to use the character now ( dynamic method invitation ), then you should explicitly be active on struts.xml, security issues, then it would be better to avoid it )

    Then you

       action class = "com.astro.action.CheckEmailAction" name = "retrieve password acne" method = "recover password" & gt; ...  

    and

      & lt; Action class = "com.astro.action.CheckEmailAction" name = "doSomethingElseAction" method = "doSomethingElse" & gt; ...  

    (Always remember that an action should not be very different logical "verb")

  2. Then, to inject For this in JavaScript, & lt; S: url & gt; Use (with name space, IF is required) and & lt; S: param> gt; (If needed) In your case, your absolute page is read at runtime so that you have to add it to the JavaScript with the URL:

      var url = "& lt ; S: url action = "recoverpasswordAction" /> email = "+ email;  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -