Solved

jquery $.ajax processing the value in type="file"

Posted on 2011-03-06
2
534 Views
Last Modified: 2012-08-14
Hi guys,

How do you add the value of what is sitting in a html form type of 'file' to be processed when in a jquery ajax function?  

i.e. this is my script so far:

$.ajax({
  type: "POST",
  url: "resultspage.php",
  data:  $("#form").serialize()+"&pic="+document.form1.pic.value,
  cache: false,
  dataType: "html",
  success: function(responseText){
    $("#displaydiv").html(responseText);
  }
});

When i run this, i get the value of:  "C:\fakepath\filename.jpg"  from the pic field.
And I can't find a way for serialize() to pass this value in either.

What is best used to capture this value so that it is just the file name?

Many Thanks
Paul



0
Comment
Question by:dev09
  • 2
2 Comments
 
LVL 15

Accepted Solution

by:
ncoo earned 500 total points
ID: 35045987
You could use regex like so to get the name:
path = document.form1.pic.value;

filename = path.replace(/^.*\\/, '');

 data:  $("#form").serialize()+"&pic="+filename,

Open in new window

0
 
LVL 15

Expert Comment

by:ncoo
ID: 35045998
If you're talking about actually uploading the file and not just getting the filename, take a look at: http://valums.com/ajax-upload/
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question