sammyjs를 사용하여 외부 API에서 json을로드하는 방법이 확실하지 않습니다.SammyJS에서 json을로드하는 중
this.get('#/contact', function(context) {
this.load('somefile.json')
.then(function(items) {
$.each(items, function(i, item) {
context.log(item);
});
});
});
HTTP를 통해로드 같은 JSON이 실패하지 않습니다하지만 :
이 코드는 잘 작동
this.get('#/contact', function(context) {
this.load('http://samedomain/api/getdata')
.then(function(items) {
$.each(items, function(i, item) {
context.log(item);
});
});
});
HTTP를 통해로드, 새미가 더 이상 개체로 JSON을보고하고, 구문 분석에 나타납니다 텍스트 데이터.
모두가 분명하므로 도메인 액세스에 문제가 없습니다.
header('Access-Control-Allow-Origin: *');
아니요 로컬 파일로로드 할 때 정상적으로 작동하는 것으로 보아 내 json 형식의 문제라고 생각합니다.
내 나머지 API는 useing된다
"Content-Type: application/json;
업데이트 : 워드 프레스에서 사용하고 다른 사람이 할 수있는 경우에 여기를 나열하려면이 옵션을 넣어
(function($) {
var app = $.sammy('#main', function() {
this.use('Template');
this.helpers({
loadJSON: function(location, options, callback) {
options = $.extend(options, {json: true});
return new Sammy.RenderContext(this).load(location, options, callback);
}
});
this.get('#/', function(context) {
this.loadJSON('http://localhost/wp-somesite/wp-admin/admin-ajax.php?action=get_all_cases')
.then(function(items) {
$.each(items, function(i, item) {
context.log(item);
});
});
});
});
$(function() {
app.run('#/');
});
}) (jQuery);
나는이 소용돌이 줄 것이다. 이것을 텍스트로 보았을 때 이제는 의미가 있습니다. 도와 줘서 고마워! – alloyking