0

How i can send form data to another domain and take response?

I try to send it by ajax, but i have error

Allow-Control-Allow-Origin.

If i send normal html form i cant get response

I need this to make API SMS.

edit: Here is ajax:

$("#submit").click(function(e)
    {
        var postData = $('#form-tab-client').serializeArray();

        $.ajax(
            {
                url : 'https://another_domain_gateway',
                type: "POST",
                data : postData,
                success:function(data, textStatus, jqXHR)
                {
                    alert('sucess');
                    console.log(data);
                    console.log(textStatus);
                    console.log(jqXHR);
                },
                error: function(jqXHR, textStatus, errorThrown)
                {
                    alert('error');
                    console.log(errorThrown);
                    console.log(textStatus);
                    console.log(jqXHR);
                }
            });
drugs-rc
  • 1
  • 1

1 Answers1

0

If you're receiving an error about Allow-Control-Allow-Origin then it simply means that CORS is disabled/unavailable to your browser address. If you do not own the target server then there's not much you can do to enable this functionality (and by the looks of it you're targeting an SMS API which you most likely do not own).

What you could do is set up a small back-end API endpoint which takes your request, executes the SMS API request and then sends the response back to the browser. This server would also need CORS enabled, rather than explaining all the steps to enable CORS you can find the information over at http://enable-cors.org/ should you take this route.

Nabeel
  • 2,272
  • 1
  • 11
  • 14
  • is another way to send form to other domain and take response? – drugs-rc Feb 25 '16 at 21:52
  • from your browser there isn't any other way to achieve this. – Nabeel Feb 25 '16 at 21:58
  • maybe like this: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/ or https://www.madebymagnitude.com/blog/sending-post-data-from-php/ ???? – drugs-rc Feb 25 '16 at 22:03
  • Have a look at http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy if you really must, but in most cases a reverse proxy is the easiest approach. – Nabeel Feb 25 '16 at 22:07