Haven't gotten around to learning anything other than what I already know (web services) so bare with me.
I have an XML file on our server and I am able to read that XML file without any issues using jQuery AJAX. It can iterate through the nodes and present the items within a drop down list no problem. Here's the code that works when connecting to a static XML
file on the server:
<script>
$(document).ready(function () {
// Load Current Terms
GetCurrentTerms();
// Store the terms drop down into a temp variable
var ddlTerms = $("#ddlTerms");
ddlTerms.change(function (e) {
var termid = ddlTerms.val();
if (termid != -1) {
alert("You selected " + ddlTerms.val());
}
else {
//$("#outputTable").hide();
}
});
});
function GetCurrentTerms() {
$.ajax({
type: 'post',
url: '/xml/currentTerms.xml',
beforeSend: function () {
//$('#ddlTerms').html('Loading...');
},
timeout: 10000,
error: function (xhr, status, error) {
alert('Error: ' + xhr.status + ' - ' + error);
},
dataType: 'xml',
success: function (response) {
$(response).find('NewDataSet').children().each(function () {
var elm = $(this);
var termid = elm.find('TermID').text();
var term = elm.find('Term').text();
$('#ddlTerms').append('<option value="' + termid + '">' + term + '</option>');
});
},
failure: function (msg) {
alert(msg);
}
});
}
</script>
Here is the jQuery Mobile drop down list in the page:
Realistically I'd prefer not to write a slew of SSIP packages for each XML file I need just because it currently works with the code I have. I'd prefer to use a web service to connect to and return the data from the database as XML. I'm off on my web service code...this is obvious as the error that is returned is a 500 - Internal Server Error.
<%@ WebService Language="VB" Class="getCurrentTerms" %>
Imports System.Collections
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.Data
Imports System.Data.SqlClient
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ScriptService()> _
Public Class getCurrentTerms
Inherits System.Web.Services.WebService
Dim oConn As New SqlConnection("CONNECTIONSTRING")
Dim oDA As SqlDataAdapter
Dim oDS As New DataSet()
<WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _
Public Function getTerms() As String
oDA = New SqlDataAdapter("SELECT * FROM termsCurrent", oConn)
oDA.Fill(oDS)
Return oDS.GetXml()
End Function
End Class
Also tried manually constructing the string witihn a while loop. All examples work when running them directly in the browser and invoking the web method directly from the browser...they return data. But the connection between the HTML page and the web service
is not working. Any ideas?
EDIT: This is what the data looks like when invoking the web service directly from the browser's debug utility:
Error function in the ajax call will have the detail of the error that is happening in the server side. You can check this to get more detail. You can also try with the json format-
I think I have other issues going on besides my code not working. I downloaded a really simple example from one of the sample sites you provided. It works when I "Start Without Debugging" from Visual Studio running within the built in web server...but fails
when I copy the files to my web server and run it. I've checked to make sure .NET Framework 4.0 Client and Extended are installed on both web server and locally and they are. Is there some setting I'm missing in IIS that's preventing this from working? I just
don't get it and this project is a must have for me. Running out of ideas....
EDIT: Just tried creating a new app pool configured for .NET Framework 4 and assigned the application to this app pool. Still no luck.
EDIT: Added JSON MIME type in IIS. Still no luck.
The web.config file is the standard web.config that is added when you add a new item from VS and select Web Configuration File.
connerissurf...
0 Points
12 Posts
Returning and parsing classic XML web service
Nov 19, 2012 09:15 PM|LINK
Haven't gotten around to learning anything other than what I already know (web services) so bare with me.
I have an XML file on our server and I am able to read that XML file without any issues using jQuery AJAX. It can iterate through the nodes and present the items within a drop down list no problem. Here's the code that works when connecting to a static XML file on the server:
<script> $(document).ready(function () { // Load Current Terms GetCurrentTerms(); // Store the terms drop down into a temp variable var ddlTerms = $("#ddlTerms"); ddlTerms.change(function (e) { var termid = ddlTerms.val(); if (termid != -1) { alert("You selected " + ddlTerms.val()); } else { //$("#outputTable").hide(); } }); }); function GetCurrentTerms() { $.ajax({ type: 'post', url: '/xml/currentTerms.xml', beforeSend: function () { //$('#ddlTerms').html('Loading...'); }, timeout: 10000, error: function (xhr, status, error) { alert('Error: ' + xhr.status + ' - ' + error); }, dataType: 'xml', success: function (response) { $(response).find('NewDataSet').children().each(function () { var elm = $(this); var termid = elm.find('TermID').text(); var term = elm.find('Term').text(); $('#ddlTerms').append('<option value="' + termid + '">' + term + '</option>'); }); }, failure: function (msg) { alert(msg); } }); } </script>Here is the jQuery Mobile drop down list in the page:
<section data-role="content"> <div class="content-primary"> <form id="form1" runat="server"> <select ID="ddlTerms"> <option value="-1">Select A Term</option> </select> </form> </div> </section>When changing this line:
url: '/xml/currentTerms.xml',
to this:
url: '/xml/getCurrentTerms.asmx/getTerms',
I get the 500 Internal Error like this:
Realistically I'd prefer not to write a slew of SSIP packages for each XML file I need just because it currently works with the code I have. I'd prefer to use a web service to connect to and return the data from the database as XML. I'm off on my web service code...this is obvious as the error that is returned is a 500 - Internal Server Error.
<%@ WebService Language="VB" Class="getCurrentTerms" %> Imports System.Collections Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Web.Script.Services Imports System.Data Imports System.Data.SqlClient <WebService(Namespace:="http://tempuri.org/")> _ <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ScriptService()> _ Public Class getCurrentTerms Inherits System.Web.Services.WebService Dim oConn As New SqlConnection("CONNECTIONSTRING") Dim oDA As SqlDataAdapter Dim oDS As New DataSet() <WebMethod()> _<ScriptMethod(ResponseFormat:=ResponseFormat.Xml)> _ Public Function getTerms() As String oDA = New SqlDataAdapter("SELECT * FROM termsCurrent", oConn) oDA.Fill(oDS) Return oDS.GetXml() End Function End Class
Also tried manually constructing the string witihn a while loop. All examples work when running them directly in the browser and invoking the web method directly from the browser...they return data. But the connection between the HTML page and the web service is not working. Any ideas?
EDIT: This is what the data looks like when invoking the web service directly from the browser's debug utility:
asteranup
All-Star
30184 Points
4906 Posts
Re: Returning and parsing classic XML web service
Nov 20, 2012 02:06 AM|LINK
Hi,
Error function in the ajax call will have the detail of the error that is happening in the server side. You can check this to get more detail. You can also try with the json format-
http://delicious.com/anupdg/pagemethod+listofposts
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
connerissurf...
0 Points
12 Posts
Re: Returning and parsing classic XML web service
Nov 20, 2012 03:14 PM|LINK
I think I have other issues going on besides my code not working. I downloaded a really simple example from one of the sample sites you provided. It works when I "Start Without Debugging" from Visual Studio running within the built in web server...but fails when I copy the files to my web server and run it. I've checked to make sure .NET Framework 4.0 Client and Extended are installed on both web server and locally and they are. Is there some setting I'm missing in IIS that's preventing this from working? I just don't get it and this project is a must have for me. Running out of ideas....
EDIT: Just tried creating a new app pool configured for .NET Framework 4 and assigned the application to this app pool. Still no luck.
EDIT: Added JSON MIME type in IIS. Still no luck.
The web.config file is the standard web.config that is added when you add a new item from VS and select Web Configuration File.