Acces .xml from Jquery with Ajax

Topics: Customizing Orchard, Troubleshooting
Aug 30, 2012 at 5:51 PM
Edited Aug 30, 2012 at 5:52 PM

Hi at there,

I'm implementing a form validation using an ajax call from a jQuery script, that have to read and compare data stored in a xml file. The file is in site root's and the script is in Register.cshtml. The first part of the routine (checking empty fields) is done but seems it's not comparing some input data with the xml.

I added the file path at Web.config but I'm still unable to read the xml. The Network tab in Firebug doesn't say anything about the file...

This is the script:

$(document).ready(function() {
            $('#enviar').click(function() {
                    if ($('#tarjeta').val() == "" || $('#telefono').val() == "" || $('#fecha').val() == ""){
                            alert("No puedes dejar ningun campo vacio!");
                    else { 	
						    Num = $.trim($('#tarjeta').val());
						    Tel = $.trim($('#telefono').val());
						    Fecha = $.trim($('#fecha').val());   
                            type: "GET",
                            url: "Clientes.xml",
                            dataType: "xml",
                            success: function(xml) {

                                        numero = $.trim($(this).find('numeroBonacompra').text());
                                        telefono = $.trim($(this).find('telefono').text());
                                        nacimiento = $.trim($(this).find('nacimiento').text());

									    if( Fecha == nacimiento || Tel == telefono ){  				
										    alert("Tus datos son correctos.\n\nGracias por confiar en nosotros.");
									    else {

And this is the related Web.config part:

      <!-- see below -->
      <clear />
      <add path="Clientes.xml" verb="*" type="System.Web.StaticFileHandler" />
      <add path="*" verb="*" type="System.Web.HttpNotFoundHandler" />

<handlers accessPolicy="Script">
      <!-- clear all handlers, prevents executing code file extensions, prevents returning any file contents -->
      <clear />
      <add name="SiteMap" 
                  path="Clientes.xml" verb="*" 
                  requireAccess="Script" />  
      <!-- Return 404 for all requests via managed handler. The url routing handler will substitute the mvc request handler when routes match. -->
      <add name="NotFound" path="*" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode" requireAccess="Script" />

Any suggestion about what I'm missing?
Thanks in advance!

Aug 30, 2012 at 8:06 PM

Did you try accessing the xml file directly using the browser's address bar? Did that work?

Aug 31, 2012 at 6:46 AM

Yes @sfmskywalker, I did and the result is:

Error de lectura XML: no se encuentra elemento
Número de línea 1, columna 1:

Anyway, I dont want it be accesible at :80 so I set requireAcces to Script at Web.config.
Do you know another method for test the acces to the xml file?

Sep 12, 2012 at 11:07 PM

How is the script supposed to be able to read that file if a browser can't?? RequireAccess="Script" has nothing whatsoever to do with this, except that no, you don't want to prevent access from a browser so this has got to be removed from your web.config.