简体   繁体   中英

integration of scala service with web app in html5

I have a Scala service and a web app in HTML5 . The web app is used to register a user to a particular group and the service is used to post the data in database. Now I want to integrate the service with the web app such that when the user fills the form and clicks the submit button the service should be called and should update the database. I am using ajax

$.ajax({
    method: "POST",
    crossDomain: true,
    url: "http://20.201.151.134:8091/update ",
    data: JSON.stringify({name:name,
                          shortid:shortId,
                          password:pass}) ,
    contentType: "application/json",
    dataType: "json"
    }).done(function( data ) {
    alert( "Data Saved: " + data );
  });

and in build.sbt file I have included the dependency

"com.thetransactioncompany" % "cors-filter" % "1.3.2"

But I'm still getting the error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'null' is therefore not allowed access.

The response had HTTP status code 400.

Can anyone plz help to resolve it?

Have you added a 'Access-Control-Allow-Origin' header in your service?

I think you should add this in order the cross origin security works properly: something like response.header('Access-Control-Allow-Origin: http://trusted.site')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM