Form data posting and Receiving response

I' am a newbie in Rust programming. I'am learning webassembly. I have created a form which accepts two string and I want them concatenated and show the concatenated result in the html page. For academic interest I want my concatenation logic to reside in Rust. Can I get some help on how to do Form POST with Javascript to Rust library and receive a response back.

<!DOCTYPE html>
<html>
  <head>
      <style>
          body {
              position: absolute;
              top: 0;
              left: 0;
              width: 100%;
              height: 100%;
              display: flex;
              flex-direction: column;
              align-items: center;
              justify-content: center;
            }
            #fps {
              white-space: pre;
              font-family: monospace;
                }
       
        </style>
    <meta charset="utf-8">
    <title>Hello wasm-pack!</title>
  </head>
  <body>
      <h1>CONCATENATION</h1>
      <form >
          <div id="fps">
        First String<input type="text" id="a1"><br>
        Second String<input type="text" id="a2"><br>
        <button type="button" id="bt" >Concatenate</button><br>
        Result<input type="type" id="re">
        </div>
      </form>
   <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script src="./bootstrap.js"></script>
  </body>
</html>

import * as wasm from "wasm-game-of-life";

$(document).ready(function()
{
    
   
});
$("#bt").click(function()
{
    
    var a=document.getElementById("a1").value;
    var b=document.getElementById("a2").value;
    const result=wasm.concat(a,b);
    alert(result);
    document.getElementById("re").value=result;
}); 

Rust code

mod utils;
 extern crate web_sys;
use wasm_bindgen::prelude::*;
 use web_sys::console;
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;


#[wasm_bindgen]
pub fn concat(s1 :&str,s2 :&str)->String
{
    
    
    let  str1=s1.to_string();
    let  str2=s2.to_string();
    console::log_1(&s1.into());
    console::log_1(&s2.into());
    let concate=str1+&str2;
    
    
    concate 
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.