Solved

getting ajax call to work

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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)

762 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