Loading an external XML file to use in local script / extension

1,012 views
Skip to first unread message

black

unread,
Mar 26, 2011, 11:25:19 AM3/26/11
to Chromium-extensions
Hi guys!

I'm new to Chrome extension development and don't have much experience
in JavaScript and XML. However, I managed to take the first steps.

My extension is very simple: it just shows the number of clients
connected to a specific server. It reads a XML file, counts the number
of "client" tags with the attribute "type" set to "c" and puts that
number in a badge. It's quite handy :).

My problem is that this currently only works when having the
"users.xml" file locally available. If I try to load it externally
from my server it doesn't work. I followed this example for loading
the XML file: http://www.w3schools.com/dom/dom_nodes_get.asp

Here's an excerpt from my script:

<script type="text/javascript">

function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}

// Works just fine
xmlDoc = loadXMLDoc("users.xml");
// Doesn't work
//xmlDoc = loadXMLDoc('http://192.168.1.3:16001/api.html?
part=status');

</script>

Karim E. Benaiges

unread,
Mar 27, 2011, 7:18:01 PM3/27/11
to black, Chromium-extensions
Hi Peter,

Have you tried adding permissions to your manifest?

Check this sample: http://code.google.com/chrome/extensions/getstarted.html

Cheers,
--
Karim E. Benaiges

> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>

black

unread,
Mar 27, 2011, 7:29:33 PM3/27/11
to Chromium-extensions
Hi Karim,

thanks a lot for your help! I added the permissions but still had the
port number in there (which is unnecessary as I found out). Now it
works just perfect This also helped me to understand why it wasn't
working:

http://code.google.com/chrome/extensions/xhr.html


On Mar 28, 1:18 am, "Karim E. Benaiges" <k.e.benai...@gmail.com>
wrote:
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.

Karim E. Benaiges

unread,
Mar 27, 2011, 7:47:09 PM3/27/11
to black, Chromium-extensions
Glad to hear that, Peter!

Oh, yes, that's a better resource :)
--
Karim E. Benaiges

> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Reply all
Reply to author
Forward
0 new messages