Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesJQuery/Ajax service DropdownList QuestionJQuery/Ajax service DropdownList Question
Previous
 
Next
New Post
4/26/2011 12:18 PM
 
I'm trying to setup a couple of dropdown lists that are populated from the database via Ajax and am trying to use jQuery to do it. I found an example @ http://www.joe-stevens.com/2010/02/23... and modified it so that it was accessing the web service instead of his default code. When I run the changes on his project everything works great but when I run it in my module I get a 404 error when it tries to get the POST url and I'm looking for ideas on how to get around the problem. My code is below....



LOGIN.ASCX



<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Login.ascx.cs" Inherits="JRSSB.Modules.Banklab.Login" %>



<%@ Register TagPrefix="dnn" Assembly="DotNetNuke" Namespace="DotNetNuke.UI.WebControls"%>



<%@ Register TagPrefix="dnn" TagName="Label" Src="~/controls/LabelControl.ascx" %>



<div id="divBanklabForm" runat="server">



    <div class="Normal Banklab_Instructions">



       <asp:Label id="lblInstructions" AssociatedControlID="divBanklabBlock" runat="server"></asp:Label>



    </div>



    <div class="SubHead Banklab_SectionHead">



      <dnn:Label id="plLoginInfo" runat="server" ControlName="divBanklabBlock"></dnn:Label>



    </div>



    <div id="divBanklabBlock" runat="server" class="Banklab_InfoBlock">



        <table>



            <tr>



                <th>



                    <dnn:label id="plBranch" runat="server" controlname="ddlBranch" suffix=":"></dnn:label>



                </th>



                <td>



                    <select id="ddlBranch">



                    </select>



                </td>



            </tr>



            <tr>



                <th>



                    <dnn:label id="plTeller" runat="server" controlname="ddlTellerNumber" suffix=":"></dnn:label>



                </th>



                <td>



                    <select id="ddlTeller">



                    </select>



                </td>



            </tr>



            <tr>



                <td align="center"><asp:Button ID="cmdLogin" runat="server"



                        Text="Button" ResourceKey="cmdLogin" CssClass="StandardButton"



                        onclick="CmdLoginClick"/></td>               



            </tr>



        </table>



    </div>



</div>







Login.ascx.cs



using System;



using System.Collections.Generic;



using System.Linq;



using System.Web;



using System.Web.UI;



using System.Web.UI.WebControls;



using DotNetNuke.Entities.Modules;



using DotNetNuke.Services.Localization;



using System.Web.Services;



using System.Collections;



using System.Data;



// ReSharper disable CheckNamespace



namespace JRSSB.Modules.Banklab



// ReSharper restore CheckNamespace



{



    public partial class Login : BanklabModuleBase



    {

#region "Constants"

        const string CoreScriptRoot  = "~/resources/shared/scripts/jquery/";



#endregion



        protected void Page_Load(object sender, EventArgs e)



        {



            //RegisterJQueryScript("jquery.min.js", true);



            DotNetNuke.Framework.jQuery.RequestRegistration();



            RegisterJavascript();

            //RegisterJQueryScript("/js/jquery.login.js");



        }



        #region "Private Methods"



        private void RegisterJQueryScript(string scriptName, bool isCore = false)



        {



            var scriptRoot = (isCore ? CoreScriptRoot : this.TemplateSourceDirectory).ToString();



            const string scriptFormat = "<script type=\"text/javascript\" src=\"{0}\" ></script>";



            var headscript = new LiteralControl



                                            {



                                                Text = string.Format(scriptFormat, ResolveUrl(scriptRoot + scriptName))



                                            };



            Page.Header.Controls.Add(headscript);



        }



        private void RegisterJavascript()



        {



            //Register the ETH script



            string jQueryEthScriptPath = this.TemplateSourceDirectory + "/js/jquery.login.js";



            Page.ClientScript.RegisterClientScriptInclude("jquery.login", jQueryEthScriptPath);



        }



        #endregion

        #region "Web Methods"

        [WebMethod]



        public static ArrayList GetBranches()



        {



            var branch = new ServiceAccess();



            var ds = branch.GetBranches();



            var arrBranches = new ArrayList();



            foreach (DataRow dataRow in ds.Tables[0].Rows)



            {



                arrBranches.Add(new { Value = dataRow["BranchNumber"], Display = dataRow["BranchNumber"] });



            }



            return arrBranches;



        }

        [WebMethod]



        public static ArrayList GetTellers(int BranchID)



        {



            if (BranchID <= 0)



            {



                throw new ApplicationException("Invalid Branch ID");



            }



            var teller = new ServiceAccess();



            var ds = teller.GetTellers(BranchID);



            var arrTellers = new ArrayList();



            foreach (DataRow dataRow in ds.Tables[0].Rows)



            {



                arrTellers.Add(new { Value = dataRow["TellerNumber"], Display = dataRow["TellerNumber"] });



            }



            return arrTellers;



        }



        #endregion

        protected void CmdLoginClick(object sender, EventArgs e)



        {

        }



    }



}







using System;



using System.Collections.Generic;



using System.Linq;



using System.Web;



using System.Web.UI;



using System.Web.UI.WebControls;



using DotNetNuke.Entities.Modules;



using DotNetNuke.Services.Localization;



using System.Web.Services;



using System.Collections;



using System.Data;



// ReSharper disable CheckNamespace



namespace JRSSB.Modules.Banklab



// ReSharper restore CheckNamespace



{



    public partial class Login : BanklabModuleBase



    {

#region "Constants"

        const string CoreScriptRoot  = "~/resources/shared/scripts/jquery/";



#endregion



        protected void Page_Load(object sender, EventArgs e)



        {



            //RegisterJQueryScript("jquery.min.js", true);



            DotNetNuke.Framework.jQuery.RequestRegistration();



            RegisterJavascript();

            //RegisterJQueryScript("/js/jquery.login.js");



        }



        #region "Private Methods"



        private void RegisterJQueryScript(string scriptName, bool isCore = false)



        {



            var scriptRoot = (isCore ? CoreScriptRoot : this.TemplateSourceDirectory).ToString();



            const string scriptFormat = "<script type=\"text/javascript\" src=\"{0}\" ></script>";



            var headscript = new LiteralControl



                                            {



                                                Text = string.Format(scriptFormat, ResolveUrl(scriptRoot + scriptName))



                                            };



            Page.Header.Controls.Add(headscript);



        }



        private void RegisterJavascript()



        {



            //Register the ETH script



            string jQueryEthScriptPath = this.TemplateSourceDirectory + "/js/jquery.login.js";



            Page.ClientScript.RegisterClientScriptInclude("jquery.login", jQueryEthScriptPath);



        }



        #endregion

        #region "Web Methods"

        [WebMethod]



        public static ArrayList GetBranches()



        {



            var branch = new ServiceAccess();



            var ds = branch.GetBranches();



            var arrBranches = new ArrayList();



            foreach (DataRow dataRow in ds.Tables[0].Rows)



            {



                arrBranches.Add(new { Value = dataRow["BranchNumber"], Display = dataRow["BranchNumber"] });



            }



            return arrBranches;



        }

        [WebMethod]



        public static ArrayList GetTellers(int BranchID)



        {



            if (BranchID <= 0)



            {



                throw new ApplicationException("Invalid Branch ID");



            }



            var teller = new ServiceAccess();



            var ds = teller.GetTellers(BranchID);



            var arrTellers = new ArrayList();



            foreach (DataRow dataRow in ds.Tables[0].Rows)



            {



                arrTellers.Add(new { Value = dataRow["TellerNumber"], Display = dataRow["TellerNumber"] });



            }



            return arrTellers;



        }



        #endregion

        protected void CmdLoginClick(object sender, EventArgs e)



        {

        }



    }



}

jquery.login.js

jQuery(document).ready(function () {



    jQuery.ajax({



        type: "POST",



        url: location.href + "/GetBranches",



        data: "{}",



        contentType: "application/json; charset=utf-8",



        dataType: "json",



        success: function(msg) {



            jQuery("#ddlBranch").get(0).options.length = 0;



            jQuery("#ddlBranch").get(0).options[0] = new Option("Select Branch", "-1");

            jQuery.each(msg.d, function(index, item) {



                jQuery("#ddlBranch").get(0).options[jQuery("#ddlBranch").get(0).options.length] = new Option(item.Display, item.Value);



            });

            jQuery("#ddlBranch").bind("change", function() {



                GetTellers(jQuery(this).val());



            });



        },



        error: function() {



            Failed to load Branches");



        }



    });



});

function GetTellers(BranchID) {



    if (BranchID > 0) {



        jQuery("#ddlTeller").get(0).options.length = 0;



        jQuery("#ddlTeller").get(0).options[0] = new Option("Loading Tellers", "-1");

        jQuery.ajax({



            type: "POST",



            url: location.href + "/GetTellers",



            data: "{BranchID:" + BranchID + "}",



            contentType: "application/json; charset=utf-8",



            dataType: "json",



            success: function(msg) {



                jQuery("#ddlTeller").get(0).options.length = 0;



                jQuery("#ddlTeller").get(0).options[0] = new Option("Select Teller Number", "-1");

                jQuery.each(msg.d, function(index, item) {



                    jQuery("#ddlTeller").get(0).options[jQuery("#ddlTeller").get(0).options.length] = new Option(item.Display, item.Value);



                });



            },



            error: function() {



                jQuery("#ddlTeller").get(0).options.length = 0;



                Failed to load names");



            }



        });



    }



    else {



        jQuery("#ddlTeller").get(0).options.length = 0;



    }



}






 
New Post
4/26/2011 12:28 PM
 
Is the following in your web.config?

<system.web>
    <webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>






Jeff Smith
VivoWare, Inc. - Open Source Social Networking Modules for DNN.
 
New Post
4/26/2011 12:52 PM
 
It wasn't but I tried adding it. It didn't make a difference. If I change the url: in the jquery to just location.href I don't get the 404 error in Firebug but still throws the error "Failed to load Branches" So I know it's going into the script in both cases. I'm guessing it has to do with the url: having /GetBranches tacked on the end but I don't know enough about jQuery and Ajax to be sure.
 
New Post
4/26/2011 1:39 PM
 
Weird. This should work, I have used it before:
$.ajax({     
    type: "POST",     
    url: window.location.href + "/SomeMethod",     
    data: "a[1]=1&a[2]=2&a[3]=3",     
    contentType: "application/json; charset=utf-8",     
    dataType: "json" 
    });

Have you tried hardcoding the location.href to see if it works?

For all my WebMethod/SOAP calls, I now use this:
http://javascriptsoapclient.codeplex....

For example:
var adDivId = "";
function GetTide(adDiv, slocation)
{
    adDivId = adDiv
    var pl = new SOAPClientParameters();
    pl.add("_location", slocation);
    SOAPClient.invoke('http://somedomain.com/desktopmodules/...', "GetTides", pl, true, GetTide_callBack);
}
function GetTide_callBack(r)
{
    r = '<font color=white>' + r.replace('�', ' ').replace('�', ' ').replace(/\r?\n|\r/g, "<br>") + '</font>';
    document.getElementById(adDivId).innerHTML=(r);
  
}

Jeff Smith
VivoWare, Inc. - Open Source Social Networking Modules for DNN.
 
New Post
4/26/2011 3:16 PM
 
I tried hardcoding the url last night with no luck. What's the a[1]=1 etc mean in your data section? Also I'm not accessing a direct webservice as you mention in your SOAPClient line. It's actually interfacing via a web reference with a WCF Service Application but it should still work as it's working fine on the non-DNN website I initially tested with.
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesJQuery/Ajax service DropdownList QuestionJQuery/Ajax service DropdownList Question


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out