jQuery.uploadãç¨ãã¦Ajaxãã¡ã¤ã«ã¢ãããã¼ã
jQueryãã¼ã¹ã§ã®Ajaxãã¡ã¤ã«ã¢ãããã¼ããæ¤è¨ãã¦ãã¾ãããã
çµå±jQuery.uploadプラグインã§å®è£
ãã¾ããã
ããç¨åº¦JavaScriptï¼jQueryã使ãããªããå®ã³ã¼ãããã¦ã³ãã¼ããã¦èªãã ãã§ã使ããã¨æãã¾ãã
ããããããã³ã¼ããå¿
è¦æå°éã«ã·ã³ãã«ã§ç¾ãã*1ã
æ¬å®¶ã®ããã¥ã¡ã³ãã¯こちら
ããããã¡ãã¨çºã¾ã£ã¦ã¾ã*2ã
以ä¸ãå®è£
ä¾*3ã
åç·ã¯ããã¡ã¤ã«é¸æãâãéä¿¡ãã¿ã³ãã§ãã
ãã©ã¦ã¶ã«è¡¨ç¤ºããéä¿¡ãã©ã¼ã
<form action="./#" method="POST" onsubmit="return false;"> <dt>ã¢ãããã¼ã</dt> <dd><input type="file" name="file" id="deckfileSelect"></dd> <dd><input type="button" value="éä¿¡" id="deckfileUploadButton"></dd> </form>
ç»é¢è¡¨ç¤ºæã«èªã¿è¾¼ã¾ããJavascriptã³ã¼ãã«è¿½å å
+// file Upload +var deckUpParams = 'a=deck_add&d=card&n='+loginName;ã// ãµã¼ããµã¤ãScriptã«æ¸¡ããã©ã¡ã¼ã¿ +$('#deckfileUploadButton').click(function() { // ãéä¿¡ãã¿ã³ãã®IDãæå® + $('#deckfileSelect').upload( // ã<input file>ãã®IDãæå® + './card_add.php', // ãµã¼ããµã¤ãã¹ã¯ãªããã®path + deckUpParams, + function(res) { + $('#deckfileSelect').attr('value', ''); // <input file>ã®valueãæ¶å» + $('#deckUtil').hide(); // ã¢ãããã¼ãæ¬ãéãã(æ²è¼ã½ã¼ã¹å¤) + + if (res.error!=undefined && res.error) { // ã¨ã©ã¼æå¦ç + alert(res.error); + hideOverLay(); // ã¢ãã«ã±è¡¨ç¤ºè§£é¤(æ²è¼ã½ã¼ã¹å¤) + return false; + } (以ä¸ãæåæã®å¦çãè¨è¼ãä¸ç¥ï¼ + }, + 'json' // resã®å½¢å¼ + ); + }); +
ãµã¼ããµã¤ãã¹ã¯ãªããã§ã¯ã
ã¾ãé常éã$_FILESã§éä¿¡ãã¡ã¤ã«æ å ±ã$_POSTã§ãã©ã¡ã¼ã¿ãåä¿¡ã§ããã®ã§ãããã§å¿ è¦ãªå¦çãè¡ãªãã¾ãã
ããã¦æå¾ã«ã
echo $response;
ã§ã$response = JOSNå½¢å¼ã®æååããåºåãã¦ããã°ã
éä¿¡å
ã®Javascript㧠res = $responseãåä¿¡ã§ãã¾ãã