javascript - How can I be able to post one image and 'two textareas values to database simultaneously using AJAX and PHP? -


Revision in this script so that I can insert images and texts together (JSON) together. With the Jquery.form.js plugin, I want to insert both image and text values ​​... Let me know if there could be any other option to do this without using the jquery.form.js plugin. I am new to Ajax .. Now help me.

The image goes to ajaximage.php and the texts go to ajtest.php, when I upload the image and text together, the image is inserted, then the text is inserted, a two lines Uses (when Textarea and Image fields are not empty), first line is used for the image and second line for text fields, this is my problem, I want to insert images and texts in a line < / P>

Script:

  & lt; Script type = "text / javascript" src = "script / jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" src = "script / jquery.form.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ('# photoimg') Live ('change', function () {$ ("# preview"). Html (''); $ ("# preview") .html ('& lt; img src = "loader.gif" alt = "uploading ...." />); $ ("# imageform") .jaxform ({target:' #preview '} ) Submit. ();});}); & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ (". Submit_button"). Click (function () {var message = $ ('# content'). Val (); var textcontents = $ ("# source" ) .val (); $ .ajax ({type: "post", url: './ajtest.php', data: {tc: message, ts: text content}, cache: true,}}}})} };   

form :

  
id = "imageform" method = "Post" enctype = "multipart / form-data" action = 'Ajaximez.fp' & gt; upload your image & lt; input type = "file" name = "photoimg" id = "photoimg" /> & Lt; / form & gt; & lt; form id = "text" method = "post" verb = '' & gt; & lt; textarea style = "width: 728px; font-size: 14px; height: 60px; font-weight: bold; size: none; "name =" content "id =" content "placeholder =" thread content "& gt; & lt; / textarea & gt; ;

Textarea style = "width: 728 px; font-size: 14px; height: 40px; font-weight: bold; resize shape: none ; "Name =" source "id =" source "placeholder =" thread source "& gt; & Lt; / Textarea & gt; & Lt; Br / & gt; & Lt; Input type = "submit" value = "post" name = "submit" class = "submit_button" /> & Lt; / Form & gt;

You can use FileApi () to get image data and it A DataURL, and send it as the ultimate (string) post, but it really depends on the browsers you are supporting. Alternatively you can use hidden iframe as form target, so your page will not be redirected. Check out this link:

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -