양식에 http://www.malsup.com/jquery/form/#ajaxForm을 사용합니다. Ajax가 서버에 이미지를 업로드하기위한 양식을 설정했습니다. IE9 없이는 모든 것이 잘 작동합니다. :). 다른 브라우저에서는 올바르게 작동하지만 서버에서 JSON 응답을 가져올 수 없습니다. success 함수 내에 alert()를 두려고했지만 성공 함수가 이벤트로드되지 않은 것으로 보입니다.IE9의 jQuery 양식 플러그인에서 JSON 응답이 없습니다.
내 JS 코드 :
$(function() {
$('#upload-image').ajaxForm({
dataType: 'json',
success: processJson
});
function processJson(data) {
var i = 0;
$.each(data, function(key, val) {
$('<li id="image_' + key + '"><input type="checkbox" name="delete_image[' + key + ']" /><img src="' + val + '" alt=""/></li>').hide().appendTo('#images').delay(i).fadeIn('slow');
i += 1000;
});
}
});
코드는 PHP에서 JSON 응답 생성 : 나는 비슷한 문제 (응답의 HTML 태그를 제거하기 위해)에 대한 몇 가지 게시물을 발견
$output = array();
foreach ($files['Filedata'] as $file)
{
$file_arr = $this->_save_image($file);
$image = ORM::factory('image');
$image->filename = $file_arr['filename'];
$image->gallery_id = $gallery_id;
$image->save();
$output[$image->id] = Route::get('uploads')->uri(array('dir' => 'images/120x120', 'file' => $image->filename));
}
$this->request->headers('Content-type','application/json; charset='.Kohana::$charset);
$this->response->body(json_encode($output));
을하지만, 도와주지 않습니다. 무엇이 잘못 되었나요?
편집 : IE 디버그 모드에서 "form.submit();"줄이 액세스가 거부되었습니다. jQuery 양식 플러그인 라이브러리 내에서. localhost에서 javascript를 실행하는 것과 관련된 일종의 보안 거부로 보입니다.
$ this-> request-> headers 라인을 주석 처리하고 확인하십시오. dataType : json을 전달하는 경우 PHP에서 json 헤더를 설정하지 않아도됩니다. – GBD
양식 작업은 무엇입니까? – GBD
이 줄은 도움이되지 않습니다. 내 작업은 양식 태그 내에서 직접 설정됩니다. – deem