Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Ajax from local system

Posted on 2008-10-04
3
Medium Priority
?
1,063 Views
Last Modified: 2010-04-21
Greetings,
I'm developing some HTML/JavaScript based training and I would like to gather user comments using Ajax to send data to my clients server. However, one of the requirement here is that the HTML content must be able to run on a local system using the file:// protocol. I have it working in IE7 such that a form is being posted to a Java servlet, and the response is being returned without a problem. However, in Firefox this does not work, it returns an access denied error. I'm currently using the Dojo JavaScript framework to do this but I expect that this is an issue with Ajax and Firefox rather then with Dojo.

Is what I'm trying to do here with Ajax even valid? Should I be able to use Ajax to make a call to a separate server from a local system? This does work if I'm using Ajax to read a file from the local system.

If what I'm doing is not valid then what are my options? I know that I could use an Iframe to load the server response in but I would like a cleaner solution.

Any help here would be greatly appreciated.
Thanks,
dv
0
Comment
Question by:vanfleet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22643392
strictly speaking the browser should NOT allow you to post data to the server via ajax since you are essentially doing cross-site scripting. However, IE always does thing its own way. Long story short, FF is doing what it is supposed to, so you will not be able to send/post the data via ajax with FF. However, if instead of ajax you were using a form, then you would be able to post/send the data to another domain without any restrictions. To avoid refreshing the page, make sure the form targets a hidden frame.Thus, my suggestion is as follows:
Assuming you are currently sending this via ajax:
user=3&sport=football

then create a form with hidden fields:
<form action="http://www.remoteserver.com" method="post" id="theForm" target="hiddenFrame">
<input type="hidden" id="user" name="user" value=""/>
<input type="hidden" id="sport" name="sport" value=""/>
</form> 
and the corresponding hidden frame:
<iframe id="hiddenFrame" name="hiddenFrame" src="" style="position:absolute;left:-100em;"/> 
then as you get the values that you need to send, update the form fields -ex:
document.getElementById("user")="joe";
document.getElementById("sport")="football"; 
and finally when you are ready to send the data, then submit the form:
document.getElementById("theForm").submit();

Open in new window

0
 

Author Closing Comment

by:vanfleet
ID: 31503132
hielo, Thank you very much for your help. I didn't want to have to do this with an IFrame but it looks like that is my best option, considering my constraints. Thanks for the clarification.
dv
0
 
LVL 82

Expert Comment

by:hielo
ID: 22660340
you are welcome.
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 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