Solved

getting ajax call to work

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now