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

HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...error calling jquery webservice error calling jquery webservice
Previous
 
Next
New Post
3/12/2012 7:27 AM
 

Hi, 

I tried calling a simple webservice using jquery in dotnetnuke but I get an error saying file not found (404). Please review my code

WEBSERVICE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;


/// <summary>
/// Summary description for TestPost
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class TestPost : System.Web.Services.WebService {


    public TestPost () {


        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    [WebMethod]
    [System.Web.Script.Services.ScriptMethod()]
    public Names[] GetNames()
    {
        List<Names> list = new List<Names>();
        DataTable dt = DataStore.GetDataTable();
        foreach (DataRow row in dt.Rows)
        {
            Names _names = new Names();
            _names.FirstName = row["Name"].ToString();
            _names.Age = row["age"].ToString();
            list.Add(_names);
        }
        return list.ToArray();
    }
    
}
public class DataStore
{
    public static DataTable GetDataTable()
    {      
        DataTable dt = new DataTable("Names");
        DataColumn dc1 = new DataColumn("Name");
        DataColumn dc2 = new DataColumn("Age");
        dt.Columns.AddRange(new DataColumn[] { dc1, dc2 });
        DataRow dr1 = dt.NewRow();
        dr1[0] = "Ahmed";
        dr1[1] = "27";
        DataRow dr2 = dt.NewRow();
        dr2[0] = "Peter";
        dr2[1] = "30";
        DataRow dr3 = dt.NewRow();
        dr3[0] = "John";
        dr3[1] = "20";
        DataRow dr4 = dt.NewRow();
        dr4[0] = "Ali";
        dr4[1] = "30";
        dt.Rows.Add(dr1);
        dt.Rows.Add(dr2);
        dt.Rows.Add(dr3);
        dt.Rows.Add(dr4);
        return dt;
    }
}


public class Names
{
    private string _firstName;
    private string _age;
    public string FirstName
    {
        get { return _firstName; }
        set { _firstName = value; }
    }
    public string Age
    {
        get { return _age; }
        set { _age = value; }
    }
}

MARKUP 

<%@ Control language="C#" Inherits="GlobalPay.Modules.MainBoard.ViewMainBoard" CodeFile="ViewMainBoard.ascx.cs" AutoEventWireup="true"%>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<%@ Register TagPrefix="dnn" TagName="Audit" Src="~/controls/ModuleAuditControl.ascx" %>  

<script type="text/javascript">
    jQuery = jQuery.noConflict();
        jQuery(document).ready(function() {
            jQuery("#Button1").click(function(event) {
                jQuery.ajax({
                     type: "POST",
                     url: "TestPost.aspx/GetNames",
                     data: "{}",
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function(msg) {
                          Success: " + msg);
                     },
                     error: function(msg) {
                          Failed: " + msg.status + ": " + msg.statusText);
                     }
                 });   
            });  
        });
     
    function AjaxSucceeded(result) {  
              result.d);
          }  
    function AjaxFailed(result) {  
          result.status + ' ' + result.statusText);  
      }    


</script>


<body> 
 
<div id="container">
    <asp:TextBox runat="server" ID="PractiseTextbox"></asp:TextBox>
    <input id="Button1" type="button" value="button"/>    
   
    <div id="footer">
     
    </div>


</div>
    
</body>

CODE BEHIND

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Web.Services;
using AjaxControlToolkit;


using DotNetNuke;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;


namespace GlobalPay.Modules.MainBoard
{
    partial class ViewMainBoard : PortalModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DotNetNuke.Framework.jQuery.RequestRegistration();


            //register the accordion script
            if (!DotNetNuke.UI.Utilities.ClientAPI.IsClientScriptBlockRegistered(Page, "ui.core.js"))
            {
                DotNetNuke.UI.Utilities.ClientAPI.RegisterClientScriptBlock(Page, 
                    "ui.core.js", "<script src=\"" + Request.ApplicationPath +
                    "/jquery-1.4.1.min.js\" type=\"text/javascript\"></script>");
            }


            ScriptManager objScriptManager;
            ServiceReference objServiceReference;


            if (DotNetNuke.Framework.AJAX.IsInstalled())
            {
                objScriptManager = ScriptManager.GetCurrent(this.Page);
                objServiceReference = new ServiceReference();
                objServiceReference.Path = ResolveUrl("TestPost.asmx");
                objScriptManager.Services.Add(objServiceReference);
            }
        }
}
}













 
Previous
 
Next
HomeHomeGetting StartedGetting StartedNew to DNN Plat...New to DNN Plat...error calling jquery webservice error calling jquery webservice


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