We help IT Professionals succeed at work.

asp.net 2.0 jquery if exists

Seven price
Seven price asked
on
295 Views
Last Modified: 2014-05-21
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

Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Seven priceFull Stack

Author

Commented:
Ok but the jquery does  a post back and returns nothing after post
Seven priceFull Stack

Author

Commented:
actually it returns 0
CERTIFIED EXPERT

Commented:
Place a debug breakpoint on your server method and see it gets hit first.
Seven priceFull Stack

Author

Commented:
tks
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.