I've two HTML pages:
1) First HTML Page (page1.html):
<html lang=en>
<head>
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js type=text/javascript></script>
<script type=text/javascript>
$(document).ready(function () {
event.preventDefault();
function json1(id,name){
this.id = id;
this.name = name;
}
id_list = Array();
id_list.push(new json1(1,TEST_1);
id_list.push(new json1(2,TEST_2);
id_list.push(new json1(3,TEST_3);
id_list.push(new json1(4,TEST_4);
id_list.push(new json1(5,TEST_5);
id_list = JSON.stringify(id_list);
document.write(id_list);
});
</script>
</head>
</html>
2) Second HTML Page (page2.html):
<html lang=en>
<head>
<meta http-equiv=Content-Type content=application/json; charset=utf-8 >
<script src=http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js type=text/javascript></script>
<script type=text/javascript>
$(document).ready(function () {
event.preventDefault();
$.ajax({
url : 'http://www.mydomain.com/page1.html',
type : 'POST',
async: false,
contentType: application/json; charset=utf-8,
dataType: json,
success: function(data){
alert(Return OK);
},
error: function(xhr, ajaxOptions, thrownError){
alert('ERROR = ' + xhr.status + ' - ' + thrownError);
}
});
});
</script>
</head>
</html>
When I execute http://page2.html, .ajax returns me:
ERROR = 200 SyntaxError - Unexpected token <
When I change the dataType: json to text, the .ajax returns me all code HTML of page1.
I need to return the JSON created in page1.html.
Anybody can help me ?
Thanks
ps: sorry about my English.