title: How Calling Web Service in HTML/PHP from java use Javascript/AJAX
body: <p>I have simple method service in java eclipse, use database postgresql but, i want to call the method in html php use javascript or ajax? I want to do insert data into database use this service and get data, how can I calling this method in html/php?</p>
  
  <p>this is my Controller</p>
  
  <pre><code>import java.util.Date;
  import java.util.List;
  
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  import org.springframework.beans.factory.annotation.Autowired;
  
  import org.springframework.web.bind.annotation.GetMapping;
  
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  
  
  import org.springframework.web.bind.annotation.RestController;
  import com.bsm.payroll.model.PayrollModel;
  import com.bsm.payroll.repository.PayrollRepoSitory;
  
  @RestController
  public class PayrollController {
  
  @Autowired
  PayrollRepoSitory payrollRepoSitory;
  
  @GetMapping(value="/payroll")
  @Produces(MediaType.APPLICATION_JSON)
  public List&lt;PayrollModel&gt; getAllPayroll(){
      return payrollRepoSitory.findAll();
  }
  
  
  //yang dipake untuk upload file di db postgresql
  @RequestMapping(path ="/coba-payroll-param", method = RequestMethod.POST)
  @Produces(MediaType.APPLICATION_JSON)
  String savebyparam(@RequestParam("company_id") String company_id, @RequestParam("nama_file") String nama_file) {
  
      PayrollModel payroll;
  
      payroll = new PayrollModel();
      payroll.setStatus("0");
      payroll.setNameFile(nama_file);
      payroll.setCompanyId(company_id);
      payroll.setCreationDate(new Date());
  
      payrollRepoSitory.save(payroll);
      return nama_file+company_id;
  
      }
  
      }
  </code></pre>
  
  <p>This is my pom.xml</p>
  
  <pre><code>     &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
          &lt;artifactId&gt;gson&lt;/artifactId&gt;
          &lt;version&gt;2.2.4&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
          &lt;artifactId&gt;javax.ws.rs-api&lt;/artifactId&gt;
          &lt;version&gt;2.0.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;optional&gt;true&lt;/optional&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>This is my HTML</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang= "en"&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
  &lt;meta http-equiv= "X-UA-Compatible" content= "ie=edge"&gt;
  &lt;title&gt; Belajar Dasar Ajax &lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Tutorial Ajax&lt;/h1&gt;
  &lt;div id="hasil"&gt;&lt;/div&gt;
  &lt;button onclick="loadContent()"&gt;Load Content&lt;/button&gt;
  
  &lt;script&gt;
      function loadContent(){
          var xhr = new XMLHttpRequest();
          var url = "http://localhost:8181/payroll";
          xhr.onreadystatechange = function(){
              if(this.readyState == 4 &amp;&amp; this.status ==200){
                  document.getElementById("hasil").innerHTML = this.responseText;
              }
          };
          xhr.open("GET", url, true);
          xhr.send();
      }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Or you have anything else for calling webservice from java to html/php, because this is my first time use this, and I don't have a picture to call java webservice to html/php</p>