I am trying to submit a HTML form from my VF page to different domain using jQuey syntax similar to below:

            $.post($(this).attr('action'), $(this).serialize(), function(json) {
            }, 'json');
            return false;

This call is getiing blocked by browser with below error:

XMLHttpRequest cannot load https://domainurl.com/sessions/create3. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://c.ap2.visual.force.com' is therefore not allowed access.

How can I resolve above issue.


1 Answer 1


This is security feature which disable the call out from java script to any other domain. Here are details about it:



Being said that there is workarounds for you.

Post your data back to VF page controller and then from your apex code make HTTP request

Here is example with explanation for your reference. http://www.saaspie.com/2014/06/05/cross-domain-ajax-requests-javascript/

The other option is using Ajax proxy.

        url : "http://www.myExternalServer.com",
        onSuccess : function(response) {
               alert("result" + response);


  • Thank you for help. I can now understand what issue is all about. Somehow I can not move my code to apex controller. API call is expected to load some authentication cookies in browser which would not be possible by using a apex code. (apex server and my browser will be at different IP address and cookies are non-transferable) . Can you help me in how can I set 'Access-Control-Allow-Origin' header in destination domain. ? Jun 2, 2016 at 6:46
  • Did you check the last link? Jun 2, 2016 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .