Solved

getting ajax call to work

Posted on 2011-09-30
3
256 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:knowlton
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36893699
Line 2, use POST instead GET

type: "POST",
0
 
LVL 9

Expert Comment

by:richard_hughes
ID: 36902458
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

0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 36903643
Yep, that was it.  It needed to be POST.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Lazy load not working with masonry js 1 22
Help with removing item from Session Array 3 31
ajax jquery 3 25
JQuery Detecting page post back 6 12
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question