Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm currently working on a Google Map extension where i want to consume an XML output from a web service that i am attempting to call. I'm not an expert in Javascript or jQuery (which i belive will help me collect the XML) so i'm learning as i go along.
Does anyone have an example of an extension that they are doing something similar what they wouldn't mind sharing in order that i can gain the knowledge needed to implement it into my extension?
This is my code which currently fails in the pareseResult function on the 'length' flag
Qva.LoadScript ("Extensions/Mouchel/GMapsRealTime/jquery-1.4.4.min.js", function () {
// For more information on doing XMLHR with jQuery, see these resources:
// http://net.tutsplus.com/tutorials/javascript-ajax/use-jquery-to-retrieve-data-from-an-xml-file/
// http://marcgrabanski.com/article/jquery-makes-parsing-xml-easy
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://localhost/CEOStatusWebService/CEOStatus.asmx/GetStatusForAllCEOs",
data: "{}",
contentType: "application/xml; charset=utf-8",
dataType: "xml",
success: ajaxCallSucceed,
failure: ajaxCallFailed
// success: function(msg) {
// alert( "Data Saved: " + msg.d );
// ServiceSucceeded(msg);
// $('#RSSContent').removeClass('loading');
// $('#RSSContent').html(msg.d);
// alert("got here");
// }
// failure: function(msg) {
// funcitonToCallWhenFailed(msg);
// }
});
});
});
function ajaxCallSucceed(response) {
alert("in success message");
$('#divLoading').hide();
var CEO = eval('(' + response.d + ')');
alert(response.d);
alert(CEO);
pareseResult(CEO);
}
function ajaxCallFailed(error) {
alert("in failed message");
$('#divLoading').hide();
alert('error: ' + error);
$('#divResults').hide();
}
function pareseResult(CEO) {
var lists = '';
for (var i = 0; i < CEO.length; i++) {
if (lists == '') {
lists = CEO.ProductName;
}
else {
lists = lists + " <br />" + CEO.ProductName;
}
}
$('#divResults').html(lists);
$('#divResults').show();
}
Thanks
Lewis
Hi Lewis.
To set a function to run every few minutes or so, just use setInterval. So if your function to run the service was called gService, you could set it to run every 120 seconds like this:
var gTimer = setInterval(gTimer, 120000);
Hi Lewis,
Could you please post the XML code that is returned when you access the page directly?
Also, are you needing to send information to the server in order to get the AJAX back? The data parameter is used to send data to the server, so it's a little strange that you'd be sending over empty brackets.
http://api.jquery.com/jQuery.ajax/
Have you tried using the $.get jQuery method instead?
Thanks
Brian
This is the contents of my returned XML. In this instance there is only one set of info however in a live situation there could be a couple of hundred records.
I don't need to send any data to the server but from the reading i had done in the cintax i was using it just needed an empty data param.
I've not looked at the $getjquery method but i'll have a look
- <string xmlns="http://tempuri.org/">
- <CEOStatus>
- <CEO>
<Number>WS6178</Number>
<Lat>51.4934183333</Lat>
<LatNS>N</LatNS>
<Long>-0.1469100000</Long>
<LongEW>W</LongEW>
<LastGPSUpdate>2024-07-23T08:28:32+01:00</LastGPSUpdate>
<IsActive>0</IsActive>
<LastStatusUpdate>2011-07-13T09:52:59.1+01:00</LastStatusUpdate>
</CEO>
</CEOStatus>
</string>
Thanks
Lewis
try replacing the ajax call with:
$.get("http://localhost/CEOStatusWebService/CEOStatus.asmx/GetStatusForAllCEOs
", function(data) {
alert($(data).length);
});
See if you get an alert box with a number besides 0 in it.
Brian
Do you mean like this?
Qva.LoadScript ("Extensions/Mouchel/GMapsRealTime/jquery-1.4.4.min.js", function () {
// For more information on doing XMLHR with jQuery, see these resources:
// http://net.tutsplus.com/tutorials/javascript-ajax/use-jquery-to-retrieve-data-from-an-xml-file/
// http://marcgrabanski.com/article/jquery-makes-parsing-xml-easy
$.get("http://localhost/CEOStatusWebService/CEOStatus.asmx/GetStatusForAllCEOs", function(data) {
alert("test");
alert($(data).length);
});
});
If so then i'm not getting any alerts coming back
thanks
Lewis
Brian
If it helps this it the complete script...
Actually, now that I look closer, I'm not sure you're including jQuery properly. If you add an alert after the
$(document).ready(function()
line of code, does it pop up? Are you properly adding the extension to the document itself by using
Qva.AddExtension(...
Thanks
Ok, got the full script.
As far as I know, you need to use the server path when including script files. So the jquery load script
Qva.LoadScript ("Extensions/Mouchel/GMapsRealTime/jquery-1.4.4.min.js", function () {
should maybe be changed to
Qva.LoadScript ("/QvAjaxZfc/QvsViewClient.aspx?public=only&name=Extensions/Mouchel/GMapsRealTime/jquery-1.4.4.min.js", function () {
I would change that and do the test I mentioned above in $(document).ready to test that jquery is being loaded at all.
Brian
I've changed the path and added an alert after the(docuemtn).ready(function... which does fire. Ive added a few more alerts into the following succeed functions and they also fire so it looks liek its making its way through the code...
if i add alert($(data).length); into my succeed function i get an undefined error
ta
Lewis
p.s thanks for you time looking at this
No problem.
Were the success functions firing before? I'm assuming that you're using the $.ajax method again if the succeed functions are firing? If so, you need to pass the successfully retrieved data into the function. Right now you have:
success: ajaxCallSucceed,
it should be
success: ajaxCallSucceed(data),
which will pass the data into your function. It looks like you call it response in that function, so the success alert would be
alert($(response).length);