Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to upload file using jquery ajax() method?

    How to upload file using jquery ajax() method? I am trying below code but i didn't get filename in save.php. share yours ideas and suggestion.

    $(document).ready(function(){
    $("#category").click(function(){
    var filename = $("#file").val();
    $.ajax({
    type: "POST",
    url: "save.php",
    data:$("#form-cover").serializeArray(),
    success: function() {
    alert("Inserted");
    }
    });
    return false;
    });
    });
    I expect to work in all browsers.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,193
    Thanks
    23
    Thanked 605 Times in 604 Posts
    While you get the file name you don't send it.
    Probably needs to be added to the data string.

    EXTRA: Any data sent back will trigger the alert. You should send the Inserted or Not Inserted message back as data.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New Coder
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    While you get the file name you don't send it.
    Probably needs to be added to the data string.

    EXTRA: Any data sent back will trigger the alert. You should send the Inserted or Not Inserted message back as data.
    yes, i understand. but i have doubt in datastring. so one example with file upload option and it saved in database.

  • #4
    New Coder
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to upload file using jquery ajax() method?

    Hi
    Upload file using jquery ajax methods as follows:-
    paste the uploadify. css file into your css folder.
    j query.upload.js in your script folder.
    download jquery.1.7.2.min.js and put it in your script folder.
    create swf folder to put uploadify.swf file.
    save uploadify- cancel. png in image folder.
    This method will be called as many time the no. of files are and as its a AJAX call so I am returning a JSON object as String valued file Name.

    The script will send you file to the server and you have to manipulate the file and store it in the folder you need.

  • #5
    New Coder
    Join Date
    Jun 2013
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to handle array of data return from ajax() call?

    Code:
    $.ajax({
    					type: "POST",
    					url: "query.php",
    					data:{cat_id:catid},
    					success: function(data) {
    					  		alert(data+"Inserted"); 
    										}
      				});
     				 return false;
    PHP Code:
    <?php
    include "config.php";
    $catid=$_POST['cat_id'];
    $sql=mysql_query("select * from image_table where catagory_id=".$catid);
    $row=mysql_fetch_assoc($sql);
    echo 
    $imgid=$row['image_id'];
    $tagquery=mysql_query("select * from tag_table where catagory_id=".$imgid);
    echo 
    $result=mysql_fetch_assoc($tagquery);
    ?>
    Expect output:
    var imagename=data[];
    var title=data[];
    var des=data[];


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •