I am trying to make an ajax call from my react component to a php file in which I am expecting the php file to return a specific output but instead I get an entire source code. Can someone help?
This is what I have on my react component.
import React from 'react';
import {Link} from 'react-router';
export default class BikePage extends React.Component {
onFormSubmitSuccess(e) {
e.preventDefault();
$.ajax({
url: 'php/new_user.php',
type: "GET",
success: function(data) {
console.log('success')
console.log(data);
}.bind(this),
error: function(xhr, status, err) {
console.log('error')
}.bind(this)
});
}
render(){
return (
<button onClick={this.onFormSubmitSuccess.bind(this)} >click here</button>
)
}
}
This is whats on my php file.
<?php
//Function to check if the request is an AJAX request
$return = 'hello'
echo json_encode($return);
?>
All I am trying to test is to get the "Hello" on my console. but instead I get the entire php file.