folgendes: Ich möchte einfach ein bild hochladen und in meine DB speichern bzw den pfad....das funktioniert auch alles wenn ich kein AJAX benutze....sobald ich das script einbaue bekomme ich die datei nicht.
hier mal der code...
Bottle template
Code: Alles auswählen
def upload_data_submit(db):
if cookie():
data = request.files.datas
sql=db.execute('SELECT ML_ID FROM ML ORDER BY ML_ID DESC')
row=sql.fetchone()
ID=str(row[0])
fotopath = do_upload(data,cookie(),ID)
print fotopath
sql=db.execute('UPDATE ML SET MLKuenstlerfotoPath = ? WHERE ML_ID = ?',(fotopath,ID,))
return template("hauptmenu")
else:
return template("login")
Code: Alles auswählen
def do_upload(data,StudName,ID):
path = 'static/images'
if data:
raw = data.file.read()
with open(os.path.join(path, StudName+ID),'wb') as files:
files.write(raw)
fotopath = path+'/'+StudName+ID
return fotopath
Code: Alles auswählen
$(".upload").bind("submit", function() {
// Ajax-Call
$.ajax({
url: "/upload_data_submit",
data: $("#dataform").serialize(),
type: "POST",
processData: false,
contentType: false,
success: function(msg)
{
/* form-div verstecken, seite nachladen & wieder einblenden (2000 ms) */
$("#contenti").hide().load("/upload_data").fadeIn(2000);
}
});