Thursday, December 4, 2014

Use a web page as a ghetto/scrape web service in any of the old web technologies which have been around since the turn of the millennium side by side with jQuery .ajax.

This is example could be a .jsp page:

<%--
   Document : pseudoservice
   Created on : Dec 3, 2014, 9:38:40 AM
   Author : tjaeschke
--%>
<%@page contentType="text/html; charset=UTF-8"%>
<%
   String foo = request.getParameter("foo");
   String bar = request.getParameter("bar");
   String result = foo + bar;
   request.setAttribute("result", result);
%>
${result}

 
 

Talk to it and back like this:

var pseudoServiceData = new Object();
pseudoServiceData.foo = "baz";
pseudoServiceData.bar = "qux";
$.ajax({
   url: "http://www.example.com/pseudoservice.jsp",
   type: "POST",
   data: pseudoServiceData,
   success: function(data) {
      $('#whatever').html(data);
   },
   error: function() {
      $('#whatever').html("Oh no!");
   }
});

No comments:

Post a Comment