Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on 

JSON - pass param?

 $.ajax({
            type: "POST",
            url: "WebGlobalMethods.asmx/NameIsAvailable",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg)
            {
                if (msg.d != "false")
                {
                    $("tr:not(:has(th),:contains('" + msg.d + "'))", "table[id*='gvShipping']").hide();
                }
            },
            error: LoadFailed
        });

Open in new window




How do I pass a string into the method NameIsAvailable?

also...wow would I pass multiple parameters?
jQuery

Avatar of undefined
Last Comment
Tom Knowlton
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

I guess I am still doing something wrong...

my jquery:
$(document).ready(function ()
{
    var loc = window.location.href;

    if (loc.indexOf("CreateNewUser") != -1)
    {
        // alert("check if user name avail");

        $.ajax({
            type: "POST",
            url: "WebGlobalMethods.asmx/NameIsAvailable",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: { "newusername": "max" },
            success: function (msg)
            {
                alert("success");
            },
            error: function (msg)
            {
                alert("failed:  " + msg.d);

            }
        });
    }
});

Open in new window



my web method (web service call):
  [WebMethod]
        public bool NameIsAvailable(string newusername)
        {
            bool nameavail = false;

            if (newusername != "")
            {
                connectToDB myDB = new connectToDB();
                object myObject = new
                {
                    LOGIN = newusername
                };
                string strPickDataReturn = myDB.getStringResult(1, "IWEB.CHECK.USERNAME", myObject);

                XmlDocument doc = new XmlDocument();
                string test = strPickDataReturn;

                doc.LoadXml(strPickDataReturn);

                System.Data.DataSet tmpDS = new DataSet();
                System.IO.StringReader stream;
                stream = new System.IO.StringReader(doc.InnerXml);
                tmpDS.ReadXml(stream);

                if (tmpDS.Tables[0].TableName == "ERRORS")
                {
                    nameavail = false;
                }
                else
                {
                    nameavail = true;
                }
            }

            return nameavail;
        }//end of web method

Open in new window




In my jquery, this part is getting called:

  error: function (msg)
            {
                alert("failed:  " + msg.d);

            }


The message that appears at runtime is

failed : undefined


Is there a way to make the message more verbose?
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

I needed single quotes around the data:

wrong:   data: { "newusername" : "max" },

correct:   data: '{ "newusername" : "max" }',


$(document).ready(function ()
{
    var loc = window.location.href;

    if (loc.indexOf("CreateNewUser") != -1)
    {
        // alert("check if user name avail");

        var msg;

        $.ajax({
            type: "POST",
            url: "WebGlobalMethods.asmx/NameIsAvailable",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: '{ "newusername" : "max" }',
            success: function (msg)
            {
                alert("success");
            },
            error: function (msg)
            {
                alert("failed:  " + msg.d);

            }
        });
    }
});

Open in new window

Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

ASKER

thx!
jQuery
jQuery

jQuery (Core) is a cross-browser JavaScript library that provides abstractions for common client-side tasks such as Document Object Model (DOM) traversal, DOM manipulation, event handling, animation and Ajax. jQuery also provides a platform to create plugins that extend jQuery's capabilities beyond those already provided by the library.

19K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo