0

I have ASP.NET MVC project with form I need to send as httpRequestObject. I'm trying for few days already to make simple XMLhttp request to 3rd party Credit card clearing company URL and get back the response with redirect which on XML format - I don't care if redirection made by iframe or popup checked all over the internet for solutions

checked all solutions here but still nothing work. checked if I'm blocked in any way like proxy or firewall, and it's not the issue.

I tried with AJAX as well -

function createMPITransaction() {
var terminal_id = "0962832";
var merchant_id = "938";
var user = "user";
var password = "password";
var url="https://cguat2.creditguard.co.il/xpo/Relay";
var xmlStr = "xml data"
var data = xmlStr;
$.ajax({
    type: "POST",
    dataType: 'XML',
    data: data,
    url: url,
    username: user,
    password: password,
    crossDomain: true,
    xhrFields: {
        withCredentials: true
    }
})
.done(function( data ) {
    console.log("done");
    alert(xhr.responseText);
    alert(textStatus);

})
.fail( function(xhr, textStatus, errorThrown) {
    alert(xhr.responseText);
    alert(textStatus);
});
alert(data);

}

I get on the console -

XMLHttpRequest cannot load "URL" No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

On network tab in chrome i see the XHR with header and form - data but no response.

any help?

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
Tzahi Kadosh
  • 397
  • 2
  • 9
  • 21
  • These may helpful: http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work or http://stackoverflow.com/questions/298745/how-do-i-send-a-cross-domain-post-request-via-javascript or http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call – Ravimallya Aug 29 '16 at 06:37
  • OR you can try this : http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource – Sunil Kumar Aug 29 '16 at 06:49

1 Answers1

1

This is a Common problem for alll developer, Cross-Origin Request Sharing -Domain AJAX request is an issue that most web developers might encounter, usually JS cannot directly communicate with a remote server from a different domain

Use Flash/Silverlight or server side as a "proxy" to communicate with remote.

JSON With Padding (JSONP) https://en.wikipedia.org/wiki/JSONP. Example https://learn.jquery.com/ajax/working-with-jsonp/

Embeds remote server in an iframe and communicate through fragment or window.name, refer here. http://www.ibm.com/developerworks/library/wa-crossdomaincomm/#N10120

See JSONP its very easy to impliment.

Patrick R
  • 6,621
  • 1
  • 24
  • 27