0

I added a web party in my mule project with the embedded Jetty server, now i'm trying to use ajax in my web project as a client and make my mule application as a server this is what i did in the jsp page:

<script type="text/javascript" src="mule-resource/js/mule.js"></script>
<script type="text/javascript">
    function register() {
        mule.rpc("/register/mesage", document.getElementById('message').value, callBack);
    }

    function callBack(message) {
        document.getElementById("response").innerHTML = "Respuesta: " + message.data + "\n";
    }
</script>

**Update:
enter image description here
enter image description here

Rajeun
  • 721
  • 2
  • 12
  • 37

1 Answers1

1

I believe if you use Ajax in your project you need the to put your JSP or HTML file under docroot folder .. Something like following example :-

enter image description here

The folder structure you have created are not correct

The Ajax connector is referring to the docroot folder in your Mule Confg in following way :-

<ajax:connector name="ajaxServer" serverUrl="http://0.0.0.0:8090/services/updates" 
        resourceBase="${app.home}/docroot"/>

For your reference :- http://www.mulesoft.org/documentation-3.2/display/32X/AJAX+Transport+Reference

And one more thing for Ajax Hosting Jetty server is not required ... Ajax is hosted using Ajax connector shown above ... so in this example above, your page is hosted in the url :- http://localhost:8090/services/updates ... And that's it !!!

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81
  • I'm a little lost, what I had in my project is a web page I created following the recommended structure for web applications on a mule application. I'm trying to do now is add some Ajax in web page that I currently have. So how while keeping the structure of my old project because I had created servlets and everything if I move something I will not get to rearrange my project. – Rajeun Apr 24 '15 at 07:55
  • For AJAX implementation you do not need Web-app or Jetty server and all the hard work.. you can put all the web pages directly under docroot folder like your index.jsp or index.html .. that's all .. your AJAX connector will pic it up from that location and will be hosted with the url you defined there in the connector .. Pls follow that I have suggested in my comments.. you can structure all your web resource under docroot folder .. pls refer :- http://www.slideshare.net/anir37/using-ajax-in-mule to get an idea on it – Anirban Sen Chowdhary Apr 24 '15 at 09:07
  • You can also refer http://www.mulesoft.org/documentation/display/current/AJAX+Transport+Reference – Anirban Sen Chowdhary Apr 24 '15 at 09:10
  • thank you for your explanation, but i should mention that i didn't create the web app to use ajax but the inverse. I would like to use ajax in my web app, you can find here http://stackoverflow.com/questions/29792855/how-to-relate-each-execution-step-of-my-mule-application-to-my-web-page/29803611#29803611 what i'm trying to do if there is a better way to do it please propose it. – Rajeun Apr 24 '15 at 09:22
  • Yes.. I understood your issue .. but my point was using AJAX you can simply host your web pages .. no need to do the hard work in creating web-apps, jetty etc .. It will push the data from your web page to Mule flow.. Now if you have an web application with you, I think you can try http://www.mulesoft.org/documentation-3.2/display/32X/AJAX+Transport+Reference .. here you see it is **Embedding in a Servlet Container** where you can put your existing **servlet** name in **web.xml** ... try to implement in that way by modifying your web application .. that is what you required – Anirban Sen Chowdhary Apr 24 '15 at 09:55
  • Here another example :- http://stackoverflow.com/questions/16035925/app-home-used-in-mule-ajax-connector-is-not-working-when-mule-project-is-convert .. check the Ajax connectore here :- `` – Anirban Sen Chowdhary Apr 24 '15 at 10:07