Solved

getting ajax call to work

Posted on 2011-09-30
3
255 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS Scroll Issue 3 117
jquery conditionally populate list boxes 2 31
Getting selected value of a dropdown with jquery 7 38
Jquery 10 20
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…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

777 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