Hi great ones,
i have a form that i save employees photos to server and URIs to DB. Doing some tests yet.
I can save in the server without no problem. the javascript callback function aint being fired .. dont know why; below is the code.. i appreciate any help on debugging it ( it doesnt show erros in javascript debugger - firefox )
HTML SNIPPET:
<form method="post" action="manipulaInclusaoFoto" id="formIncluiFotoFunc">
<table width="720" border="0" cellspacing="1" cellpadding="0" class="text" id="tableFoto" style="display:none;">
<tr>
<td class="text_bold" style="color:cb0020"><h3>DADOS PESSOAIS</h3></td>
</tr>
<tr>
<td><input type='hidden' name='next_pk' value="${XML(nextpk)}"/></td>
</tr>
<tr>
<td class="text_bold" style="color:cb0020">Foto:</td><input class='form' type="file" name="upload_file" id="upload_file"/><br/>
<td><span id='foto' style='border:1px solid red;'></span></td>
</tr>
<tr>
<td><input type='submit' class='botao' value='SalvarFoto' /></td>
</tr>
</table>
</form>
======================================================
controller.py snippet:
@expose("json")
def manipulaInclusaoFoto(self, **kw):
from model_rh import *
html = upload(kw['upload_file'])
return dict(html=html)
=========================================================
upload function
def upload(upload_file):
import os
UPLOAD_DIR = cherrypy.config.get("funcionario.fotos.uploads", os.path.join(os.getcwd(), "uploads"))
if not os.path.exists(UPLOAD_DIR):
os.makedirs(UPLOAD_DIR)
data = upload_file.file.read()
target_file_name = os.path.join(os.getcwd(), UPLOAD_DIR,upload_file.filename)
# open file in binary mode for writing
f = open(target_file_name, 'wb')
f.write(data)
f.close()
info = {}
info['uri_img'] = target_file_name
info['msg'] = ""
return info
it returns uri_msg correctly to controller.py ...
==================================================
javascript snippet ( jquery is used):
$('#formIncluiFotoFunc').ajaxForm(
{dataType:'json',
success: retornoInclusaoFoto}
);
javascript code execute on onLoad event successfully ( tested with some alert())
======================================================
retornoInclusaoFoto ( javascript callback function)
function retornoInclusaoFoto(data){
$("#foto").html("<img src='"+data.html.uri_img+"' border='1'/>");
}
================================================
its doesnt execute retornoInclusaoFoto ... just cant see why.. kinda blind...
any tip?