-3

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?

Steve Willcock
  • 23,749
  • 4
  • 41
  • 39
  • 1
    Can you provide a little more information about your Scala service. Is this using the Play framework for example, or something else? The CORS filter that you are using there seems to require a servlet container. – Steve Willcock Jun 10 '15 at 07:07
  • Please explain more about your project. What do you mean with Scala service? Is it based on Spary? Play? Servlet Container? or what? – Soroosh Sarabadani Jun 10 '15 at 07:32
  • I think this question is not related with scala itself, but CORS filter. – Thiago Pereira Jun 10 '15 at 13:02
  • it is using spray frame work.it is a rest service using POST.i m trying to insert the data into database using this service. – Ankita Barbie Jun 11 '15 at 07:46

1 Answers1

1

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')

codejitsu
  • 2,854
  • 2
  • 19
  • 32
  • 1
    or even `response.header('Access-Control-Allow-Origin: *')` to allow requests to be made from any hosts – maks Jun 10 '15 at 09:09
  • i m using spray framework.i m new to scala so can u plzz be little precise as to where to add this response.header() – Ankita Barbie Jun 11 '15 at 07:48
  • @AnkitaBarbie look here for example: http://stackoverflow.com/questions/19396187/how-do-i-specify-spray-content-type-response-header – codejitsu Jun 11 '15 at 08:11