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 )


<form method="post" action="manipulaInclusaoFoto" id="formIncluiFotoFunc">
  <table width="720" border="0" cellspacing="1" cellpadding="0" class="text" id="tableFoto" style="display:none;">
              <td class="text_bold" style="color:cb0020"><h3>DADOS PESSOAIS</h3></td>
              <td><input type='hidden' name='next_pk' value="${XML(nextpk)}"/></td>
                <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>
                <td><input type='submit' class='botao' value='SalvarFoto' /></td>

controller.py snippet:

        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):
        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')
        info = {}
        info['uri_img'] = target_file_name
        info['msg'] = ""
        return info

it returns uri_msg correctly to controller.py ...

javascript snippet ( jquery is used):

                                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?

Edited 7 Years Ago by Nick Evan: Added code-tags

This article has been dead for over six months. Start a new discussion instead.