• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XMLHtmlRequest return Undefine

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to POST XML data to the external website using FireFox. Post version for IE works fine, but when I use XMLHtmlRequest to post the data in the FireFox I get undefined


var oHTTP = new XMLHttpRequest();
alert("oHTTP" oHTTP.value);

alert display's undefine.

JavaScript ---------------




[ July 14, 2008: Message edited by: Bear Bibeault ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never heard about the value property of a XMLHttpRequest object. Can I ask where you got that information from.

Eric
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

As far as I know XMLHtmlRequest is used to send the request from the JavaScript to the external website. I have a XML data which need to be send to the external website for processing for IE browser I have used ActiveX object
var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var oXML = new ActiveXObject("Microsoft.XMLDOM");
which don't work in FireFox, that the reason I am using
var oHTTP = new XMLHttpRequest();

Thanks
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no oHTTP.value.

Here is an entry level tutorial on the subject.

Eric
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric,

Then How I am suppose to handle open("Post",url,sync) to post the XML string to the external url in Firefox to process it. and secondly if you can suggest the below equivalent code for FireFox that will be Great as this below Javascript works fine in IE and not in FireFox.


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of dealing with all this browser-specific mess, why not just employ a JavaScript library such as Prototype or jQuery that handles all of that for you?
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where I can fine this library's and how can I use then do you have any examples which I can refer. I need to fine the solution at the earliest, did couple of search and using XMLHttpRequest was the best available and simple option to implement.
But i am still confuse why doesn't XMLHttpRequest works. I am intiallizing it and then to it return undefined?

Thanks,
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the link i did not post: http://developer.apple.com/internet/webcontent/xmlhttpreq.html

Eric
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll find Prototype here, and jQuery here. There are a lot of other libraries, by the way, but these are the two that I think are the easiest to adopt and are the least invasive.

I usually recommend jQuery as the easiest to adopt quickly.

As an example, to load an HTML fragment from a URL into a div named targetDiv is as easy as:

That's it. And all browser-weirdnesses are handled.
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eric,

I have used the same structure only difference it rather then using the GET i am using the POST but it doesn't seems to be working. Any suggestion.
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for you suggestion will I be able to post the XML data with Jquery ? Just want to be sure before I start it implementation
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. For that, you would use one of the more general methods such as $.get() or $.post().
[ July 14, 2008: Message edited by: Bear Bibeault ]
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Do I need to create a handler for to use jquery? since if I use $.post("sada.com") in my JavaScript it throws and Error. I have download the Jquery and is include in my JSP.
Any help is appreciated.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the error message?

Are you trying to post to a different domain than the one you are on?

Eric
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes that right eric I am trying to post to different domain. Undefined is the error.when i used XMLHttpRequest handler to post the Sting to the External URL
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never say "I got an error"

Say "Here is the error that I got:" and include the full and accurate text of the error (and any other information that goes with it).

Otherwise, we can only guess.
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the entire code Bear, and Error is "Undefined"



 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The XMLHttpRequest object can not post to a different domain. JavaScript has the same orgin policy meaning you are stuck with only your domain. If you want to talk to another domain you need to either look into a JSON request or set up a serverside proxy.

Eric
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

only one common problem i found with your code
send current time to server as i have mentioned, you will not face this problem any more.And this will also help you to work on different browsers.


Thank You.
Have a Nice Time.

-Santosh


var xhReqs = null;
function createXMLHttpRequest() {
if (typeof XMLHttpRequest == 'undefined') {
// IE
try {
xhReqs = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhReqs = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhReqs = new XMLHttpRequest();
}
}

function responseXmlParserVote(operation,id) {

if (xhReqs == null) {
createXMLHttpRequest();
}
if (xhReqs.readyState != 0) {
xhReqs.abort();
}
var url;

url= "<%=request.getContextPath()%>/action.do?operation=" + operation+"&id="+id+"&";


var d = new Date();
var ctime = d.getTime();

url += "&time="+ctime;

xhReqs.open("POST", url, true);

xhReqs.onreadystatechange=function() {
if (xhReqs.readyState == 4) {
var root = xhReqs.responseXML.documentElement;

};
xhReqs.send(null);
}
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SantoshkumarJeevan Pawar:

"POST" requests do not get cached so adding a timestamp is not going to make a difference in this case. For you information: there is a better way of handling the cache and there is no timestamp needed.

<blockquote>code:
<pre name="code" class="core">
xmlhttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
</pre>
</blockquote>

Eric
 
Manu Garg
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks SantoshkumarJeevan Pawar this doesn't seems to be working too. I need the XML string to be posted to the external URL.

Bear, Can you provide some input on the JQuery you have mentioned ?

Thanks,
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel like a broken record. The XMLHttpRequest object can not talk to an outside domain. You would have to use a serverside proxy to talk to another domain.

Eric
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic