JSFiddle - React, Tailwind, and code Playground
HTML
<a id="ajaxLink" href="#" target="_blank">link</a>
<input type='submit' value='test' id="test"/>
<input type="hidden" id="query" value="myVal" />
JavaScript
$('#test').click(function() {
alert('called');
var url1='http://web.aspasia.net/pls/grainger-training/prospect_public?fname=test&apptype=BUY&title=Mr&initials=t&lname=test&addr1=test&town=test&postcode=12345&phone_o=123456790&rl=http://google.com';
makeCorsRequest();
});
$('#ajaxLink').click(function() {
alert('called')
});
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
// XDomainRequest for IE.
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
}
// Helper method to parse the title tag from the response.
function getTitle(text) {
return text.match('<title>(.*)?</title>')[1];
}
// Make the actual CORS request.
function makeCorsRequest() {
debugger;
// All HTML5 Rocks properties support CORS.
var url = 'http://web.aspasia.net/pls/grainger-training/prospect_public?fname=test&apptype=BUY&title=Mr&initials=t&lname=test&addr1=test&town=test&postcode=12345&phone_o=123456790&rl=http://google.com';
var xhr = createCORSRequest('POST', url);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader('X-Alt-Referer', 'http://www.google.com');
if (!xhr) {
alert('CORS not supported');
return;
}
// Response handlers.
xhr.onload = function () {
var text = xhr.responseText;
var title = getTitle(text);
alert('Response from CORS request to ' + url + ': ' + title);
};
xhr.onerror = function () {
alert('Woops, there was an error making the...