Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

getting ajax call to work

Here is my ajax call:

        $.ajax({
            type: "GET",
            url: "WebGlobalMethods.asmx/HelloWorld",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: TheTextFound,
            error: LoadFailed
        });

        function TheTextFound()
        {
            alert("success");
        }

        function LoadFailed()
        {
            alert("did not work");
        }

Open in new window






Here is the web service code:

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

namespace Campus_Webstore
{
    /// <summary>
    /// Summary description for WebGlobalMethods
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 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 WebGlobalMethods : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
}

Open in new window




So far it is failing  ( I get the alert that says "did not work" )


I could use some help.  Thanks!

Tom
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello knowlton

As leakim971 said, try the attached code.

Thanks,

Richard
$.ajax({
            type: "POST",
            url: "WebGlobalMethods.asmx/HelloWorld",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: TheTextFound,
            error: LoadFailed
        });

        function TheTextFound()
        {
            alert("success");
        }

        function LoadFailed()
        {
            alert("did not work");
        }

Open in new window

Avatar of Tom Knowlton

ASKER

Yep, that was it.  It needed to be POST.