1

Yes, I would have all frames under the same URL.

It seems to save a decent amount of typing if I just submit a form to an iframe, get the contents of the frame document, and do whatever I need with them on the parent page. (Display errors with the form after submission, for example)

So why not just submit to a frame instead of AJAX?

EDIT: https://stackoverflow.com/a/362743/870729

While iframes are meant for content embedding, one must remember that they are used quite often for other reasons. One example would be a dynamic upload form, that displays the upload progress with jQuery or something.

In my case specifically, when a user submits a form, I want to return ONE number.

For example, if the user submits the signin form, and the result is 0, the username they entered does not exist. 1 would be an incorrect password, etc.

I would do something like this in JS then:

 if(response==2){ //let's just say that '2' is "no errors"
   displayMessage("You have signed in successfully!");
 }

EDIT:

Thank you everybody for your answers. I will just use AJAX in this case. Special thanks to @cale_b.

Community
  • 1
  • 1
Ricky Yoder
  • 561
  • 2
  • 11
  • 22
  • Read this: http://stackoverflow.com/a/362743/870729 – random_user_name Aug 13 '13 at 22:59
  • Good point, but just in case, let me make an edit. – Ricky Yoder Aug 13 '13 at 23:09
  • Fair enough. The question maybe comes down to: why do you want to use an iFrame? based on your comments on the answers below, it sounds like you'd prefer an iFrame? With jQuery, ajax is trivial to execute, fast, and give you a lot of flexibility. With ajax, you could literally return a single character / number as you explained. – random_user_name Aug 13 '13 at 23:24
  • Yes, but I typically don't use jQuery. I just don't like it because of the fact that there's so many features it offers, but I only want a select few. (AJAX would probably be one of them) So, the reason I wanted to use an iframe in the first place was because I don't want to use jQuery, and I don't want to have to type all the stuff that I normally do when making an AJAX request. Just a bit less typing, basically. – Ricky Yoder Aug 13 '13 at 23:27
  • Then use an iFrame. It's your call. I get your point, and at the same time if your host provider supports compression, jQuery (minified) is a 26k asset that gives you lots of flexibility. Alternatively, there's [Ajax Toolbox](http://www.ajaxtoolbox.com/) which just gets you Ajax, and is less than 20% the size of jQuery. Or, use an iFrame! – random_user_name Aug 13 '13 at 23:31
  • I'll use Ajax Toolbox. Thanks. – Ricky Yoder Aug 13 '13 at 23:35

2 Answers2

0

That would work, but it may be difficult to get the information from your iframe to your parent page. What event would you use, frames[0].onload = function(){}?

StackSlave
  • 10,613
  • 2
  • 18
  • 35
0

As with this answer to Are iframes considered 'bad practice'?, iframes will cause the browser to look like it's loading, and will make the browser's back button navigate the iframe back to the previous state. This might be what you want, and it might not be.

Community
  • 1
  • 1
gurumike
  • 106
  • 1
  • 5
  • Oh right. No, that isn't what I'd like. Isn't there a way to stop that from happening, though, and make it so that the navigation buttons only access the top window? – Ricky Yoder Aug 13 '13 at 23:16