paul40
posted this
29 November 2018
Hi,
I have added a standard form via Nicepage. I then click the submit button > Form (tab) > Send to and leave the default "#". If I try and add "javascript: sendData()" my function is not invoked as this code is added to the "action" attirbute of the form.
Therefore, I run some custom javascript in a nicepage HTML block at the bottom of my page to add a click event to my forms Submit button so that my function will run...
var submitlink = document.getElementsByClassName("u-btn-submit")[0];
submitlink.onclick = function( event ) {
// if (event.preventDefault) event.preventDefault();
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://logicappurl");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var item = {
name: document.getElementsByName("name")[0].value,
email: document.getElementsByName("email")[0].value,
phone: document.getElementsByName("phone")[0].value,
message: document.getElementsByName("message")[0].value
};
// document.getElementsByName("sent message").classList.remove("hidden");
xhr.send(JSON.stringify(item));
// return false;
};
Everything works as epxected but I get a jQuery error...
Access to XMLHttpRequest at 'file:///private/var/folders/4r/s7z5_ylj3w79ycvbllv8ttn80000gn/T/Nicepage/chrome/index.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
send @ jquery.js:6
ajax @ jquery.js:6
submit @ nicepage.js:7
dispatch @ jquery.js:4
v.handle @ jquery.js:4
trigger @ jquery.js:4
(anonymous) @ jquery.js:5
each @ jquery.js:4
each @ jquery.js:4
trigger @ jquery.js:5
b.fn.(anonymous function) @ jquery.js:6
click @ nicepage.js:7
dispatch @ jquery.js:4
v.handle @ jquery.js:4
Hi,
I have added a standard form via Nicepage. I then click the submit button > Form (tab) > Send to and leave the default "#". If I try and add "javascript: sendData()" my function is not invoked as this code is added to the "action" attirbute of the form.
Therefore, I run some custom javascript in a nicepage HTML block at the bottom of my page to add a click event to my forms Submit button so that my function will run...
var submitlink = document.getElementsByClassName("u-btn-submit")[0];
submitlink.onclick = function( event ) {
// if (event.preventDefault) event.preventDefault();
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://logicappurl");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var item = {
name: document.getElementsByName("name")[0].value,
email: document.getElementsByName("email")[0].value,
phone: document.getElementsByName("phone")[0].value,
message: document.getElementsByName("message")[0].value
};
// document.getElementsByName("sent message").classList.remove("hidden");
xhr.send(JSON.stringify(item));
// return false;
};
Everything works as epxected but I get a jQuery error...
Access to XMLHttpRequest at 'file:///private/var/folders/4r/s7z5_ylj3w79ycvbllv8ttn80000gn/T/Nicepage/chrome/index.html' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
send @ jquery.js:6
ajax @ jquery.js:6
submit @ nicepage.js:7
dispatch @ jquery.js:4
v.handle @ jquery.js:4
trigger @ jquery.js:4
(anonymous) @ jquery.js:5
each @ jquery.js:4
each @ jquery.js:4
trigger @ jquery.js:5
b.fn.(anonymous function) @ jquery.js:6
click @ nicepage.js:7
dispatch @ jquery.js:4
v.handle @ jquery.js:4