8 Replies - 1330 Views - Last Post: 08 July 2011 - 06:22 AM

#1 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 01:54 PM

Hi, I was told that I can upload files by using a ajax effect. I mean using a hidden iframe.

the problem is I don't fully understand what they are doing and what is happening behind the scenes.

They say to make your form target your iframe. the form will post to the iframe. The iframe will be blank it won't have a url etc.

So I am cluless as to what is actually happening. How will you be able to submit the data if your posting them to an iframe that is blank???

I want to know the whole concept.

Is This A Good Question/Topic? 0
  • +

Replies To: how to upload a file via ajax or make a work around like ajax effect

#2 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 02:49 PM

AJAX allows you to make an asynchronous (sp?) request to Javascript/PHP.

In order to upload a file, you'll need to have a firm grasp on PHP or another server side language.

Basically, AJAX will call a Javascript function or URL (often the PHP URL) and will do that without reload the page (that's where asynchronous comes from).

I'm not sure why you'd need an iframe, when you do it via PHP, ASP, JSP, Ruby, etc.

I'm sorry, but you can't edit a database to store the picture with AJAX/Javascript alone.

I hoped this helped! Anyother questions still?
Was This Post Helpful? 0
  • +
  • -

#3 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 02:55 PM

I was told you can't upload files via ajax. ajax dosen't support uploading files.

I have to upload images. I was told there is a work around where you use an iframe. I still can't understand the concept of how you use the iframe to post the files to a php file.
Was This Post Helpful? 0
  • +
  • -

#4 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 02:59 PM

No, AJAX can't upload ANYTHING to a database/server without the help of a server-side programming language/script.

As far as I'm aware, there is no work around to do that, because Javascript lives on the client (browser), while PHP lives on the server.

I suggest looking up a server-side language. Since I know PHP, I figured I'd give you some links.
How to upload files via PHP:
http://php.net/manua...file-upload.php
http://www.w3schools...file_upload.asp

Interacting with a database:
http://www.w3schools...mysql_intro.asp
Was This Post Helpful? 0
  • +
  • -

#5 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 03:24 PM

I know php. I can upload files with php. It's that I don't want the page to be refreshed or redirected.

I want an ajax type of effect. Where it uploads the files without redirecting the user to another page or refreshing the webpage.
Was This Post Helpful? 0
  • +
  • -

#6 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 06 July 2011 - 03:25 PM

So you call the PHP script from AJAX

xmlhttp.open("POST","uploadfile.php",true);



Boom! Done. Just make sure the PHP file will upload the files.
Was This Post Helpful? 0
  • +
  • -

#7 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 07 July 2011 - 10:33 AM

View Postmaniacalsounds, on 06 July 2011 - 04:25 PM, said:

So you call the PHP script from AJAX

xmlhttp.open("POST","uploadfile.php",true);



Boom! Done. Just make sure the PHP file will upload the files.



are you sure this would work? Cuz many people are saying ajax can't upload files.

It only can pass variables to a server sided script. This is why they say you need a work around by using a iframe to submit files like images in a ajax effect way where nothing refreshes.
Was This Post Helpful? 0
  • +
  • -

#8 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 469
  • Joined: 27-June 10

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 07 July 2011 - 10:35 AM

I've NEVER heard of such a claim. AJAX alone can't uplaod a file, true. However, when AJAX calls a PHP file that can, it can, yes.

Tutorial for POST requests in AJAX:
http://www.openjs.co..._using_post.php
Was This Post Helpful? 0
  • +
  • -

#9 hockey97  Icon User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

Re: how to upload a file via ajax or make a work around like ajax effect

Posted 08 July 2011 - 06:22 AM

ya, but what I am told the files won't be passed via ajax. Even if you use a php file. I am using a php file. but can't get multiple files submitted.

I need to submit about 8 possible images at one time. I want it via a ajax effect where the user dosen't get redirected nor gets the page refreshed.

here is one article that shows what I am talking about:

http://www.finalwebs...-upload-example


they said you can't submit a file to a php file via ajax. ajax won't pass the file. It will only pass on data.

So you need to find a work around.. they are saying to have a hidden iframe. and to have that iframe run your php script and then have the form target that iframe. It should pass the files to the php file to submit it.

I already got the php all written. My problem is passing the files to the php file. So far not doing good.

I also at the same time need to manipulate the content inside a iframe. Cuz I also got a html document in a iframe that I need to when clicking on a check box to check if it's checked then add some new html tags inside a div.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1