0

I am trying to submit a form using jquery ajax in POST method. The action of the form is in another domain.

I have tried almost everything but getting the same error:

Failed to load http://localhost:3000/api/job-entry: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3400' is therefore not allowed access.

Here is what I tried:

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  dataType: 'json',
  "crossDomain": true,
  contentType: 'application/x-www-form-urlencoded',
  // "headers": {
  // "accept": "application/json",
  //  "Access-Control-Allow-Origin": "*"
  // },
  xhrFields: { withCredentials: true },
  success: function(res) {
    func(res)
  },
  error: function(e, e2) {
    func({ e2: e2, e: e })
  }
});

I cannot use jsonp as it is POST method.

Is there any other way to submit a form in post method from one domain to another domain???

Actually, I am trying to create a mobile app in Cordova. So, there is no way of server-side request.

Any help will be appreciated

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
Hello World
  • 2,673
  • 7
  • 28
  • 60
  • Related: [Cross-domain requests using PhoneGap and jQuery doesn't work](https://stackoverflow.com/questions/10173427/cross-domain-requests-using-phonegap-and-jquery-doesnt-work) – Jonathan Lonowski Jul 29 '18 at 15:58
  • It was helpful. But first I am now creating the app in the local server where I cannot apply that solution – Hello World Jul 29 '18 at 16:02
  • 1
    Add the [`Access-Control-Allow-Origin: *`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin) header [Read more](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). – Louys Patrice Bessette Jul 29 '18 at 16:13
  • 1
    @LouysPatriceBessette Yes, it worked. The problem was in the backend but I have been trying in the frontend. Thank you for suggesting. – Hello World Jul 29 '18 at 16:29

0 Answers0