Avatar of Seven price
Seven price
Flag for United States of America asked on

asp.net 2.0 jquery if exists

Not checking correctly. It stops where the alert(Jsonstring) then it will not continue.

$(document).ready(function () { 
var JSONObject = new Object; //Initialize a new JSON object as this is the most common mistake making a JSON object 

$('#btn').click( 
function () { 

JSONObject.name = $('#lid').val().toString(); //Read Data from a textbox with id = lid 
JSONstring = JSON.stringify(JSONObject); //Stringyfy in JSON format 
alert(JSONstring); //Alert to check your request you can remove later on   /// Error it stops here does not post. but returns name
$( ".result" ).html( JSONstring )
$.ajax({ 
type: "POST", 
url: "test.aspx/checkExists", // Request Post to page Test1.aspx and calling method GreetingMessage 
data: JSONstring, // Pass Request String 
contentType: "application/json; charset=utf-8", 
dataType: "json", 
success: function (response) { 
//alert(response.d.toString() + " good"); 
$( ".result" ).html( response.d.toString() );
}, 
error: function (xhr, ajaxOptions, thrownError) { 
alert(xhr.status); 
alert(thrownError); 
$( ".result" ).html( response.d.toString() );
} 
}); 
} 
); 

}); //close ready

Open in new window



server side.
 public static string checkExists(string name) //Method should be declared as static 
        {
            return "your name exists " + name + Environment.NewLine + "this is your name";
        }  

Open in new window

jQueryASP.NET

Avatar of undefined
Last Comment
Seven price

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sammy

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Seven price

ASKER
Ok but the jquery does  a post back and returns nothing after post
Seven price

ASKER
actually it returns 0
Sammy

Place a debug breakpoint on your server method and see it gets hit first.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Seven price

ASKER
tks