Hello,
I wish to post some data to a PHP script using an inputText and a Submit button. I have created an inputText box and a Submit button in my wix editor, and have written the below code:
import {fetch} from ‘wix-fetch’ ;
export function button3_click(event) {
console.log( "value: " + $w( “#input4” ).value) //to check the value sent
fetch( "http://www. mydomain .com/test.php" , {
“method” : “post” ,
“headers” : {
“Content-Type” : “application/x-www-form-urlencoded”
},
“body” : “mobileno:” + $w( “#input4” ).value
} )
.then( (httpResponse) => {
if (httpResponse.ok) {
console.log( “success” )
return httpResponse.json();
} else {
return Promise.reject( “Fetch did not succeed” );
}
} )
.then( (json) => console.log(json.someKey) )
. catch (err => console.log(err));
}
On button click, I am always getting ‘TypeError: Failed to fetch’ error. The PHP script runs fine if I put it in the browser and echos a string.
How do we send a simple text to a PHP file?
Any leads would help,
Thank you.