I would like to know what solution I can use in order to have a REST api with js as the client and php as the server side of the api?
I have tried using iFrame, channel files and custom headers.
But none has worked.
- I would like to know how I should do it.
Thanks in advance.
Things I have tried already:
1)iFrame:
$(document).ready(function(){
$("#fff").contents().find("#rrr").submit();
})(jQuery);
-------------
<body>
<p id="hello">Hello World</p>
<iframe id="fff" src="#">
hi
<form id="rrr" action="http://mydomain/rest/rest.php" method="get">
<input type="text" value="testy" name="check" />
</form>
</iframe>
</body>
-->returns nothing.
2) Channel file:
file on server(js):(conjs.js)
function getDev(callback){
jQuery.ajax({
url: 'rest.php',
type: 'GET',
data: 'name=John', // or $('#myform').serializeArray()
success: function(data) {
callback('Get completed '+data);
}
});
}
------------------
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
<script src="http://mydomain/rest/conjs.js"></script>
</head>
<body>
<p id="hello">Hello World</p>
<script type="text/javascript">
getDev(function (response) {
alert(response);
});
</script>
</body>
</html>
-->returns nothing.
3)Php headers:
switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://jsbin.com': case 'https://jsbin.com':
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
break;
}
-->returns nothing.
None has worked so far.