Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi to all.

i have jquery function, that running successfully, what problem is that when i am trying to fetch string from this method it will come undefine. but when i use json.stringfy the reslut is coming : {"d":"epension"}
i want to user only epension as a string.

here is code :
JavaScript
function testdata() {

           $.ajax({
               type: "Post",
               url: "http://localhost:49410/code/Home.aspx/test",
               data: '{}',
               contentType: "application/json; charset=utf-8", // content type sent to server
               datatype: 'json',
               success: function (response) {

                   
                   $('#tableContent').html(response);
                   

               },
               failure: function (response) {
                   alert(json.stringfy(response));
               }

           }); 

       }
Posted

So just change to:

JavaScript
$('#tableContent').html(response.d);


And I don't really see any need to JSON for returning a string. Just do:

HTML
Response.Write("expension");

in your page, and

JavaScript
$.ajax({
{SNIP!}
     datatype: 'html',
     success: function (response) {
 
                   
                   $('#tableContent').html(response);
                   
 
               },
{SNIP!}
});


it will return your response in plain text and add it to your DOM.
 
Share this answer
 
as per you.
you json object is :{"d":"epension"}

you can access it as
JavaScript
success: function (response) {
 //$('#tableContent').html(response);
alert(response.d);//it will show you "epension"
           },


for error you can try this..

JavaScript
error: function (jqXHR, exception) {
                alert(":-(");
		if (jqXHR.status === 0) {
                    errormsg = 'Not connect.\n Verify Network.'; ;
                } else if (jqXHR.status == 404) {
                    errormsg = 'Requested page not found. [404]'; ;
                } else if (jqXHR.status == 500) {
                    errormsg = 'Internal Server Error [500].'; ;
                } else if (exception === 'parsererror') {
                    errormsg = 'Requested JSON parse failed.'; ;
                } else if (exception === 'timeout') {
                    errormsg = 'Time out error.'; ;
                } else if (exception === 'abort') {
                    errormsg = 'Ajax request aborted.'; ;
                } else {
                    errormsg = 'Uncaught Error.';
                }
                $('#results p').html(errormsg);     
            }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900