Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have function and i try to call in java script and also try to call that data in alert box but alert box not populate code is


I try this

What I have tried:

C#
<script type="text/javascript">
$('#submitchart').click(function () {
     //alert("i");
    var webmethod = 'WebForm1.aspx/Jqufunc';

    $.ajax({
        type: 'POST',
        url: webmethod ,
        data: JSON.stringify({ yearP: $('#yearValue').val() }),
        contentType: 'application/json;charset=utf-8',
        dataType: 'json',
        success: function (response) {
            debugger;
            alert(JSON.stringify(response.d));
            var data1 = response.d.split('*')[0];
            var data2 = response.d.split('*')[1];

            alert(data1);
            alert(data2);                       
        }   

    });
});




 </script>

any solution?
Posted
Updated 2-Jun-16 1:46am
v2
Comments
Suvendu Shekhar Giri 1-Jun-16 4:21am    
tried debugging?
John C Rayan 1-Jun-16 4:35am    
is your ajax call hitting the server method? show us your #jqufunc.
Sergey Alexandrovich Kryukov 1-Jun-16 16:11pm    
Solution of what problem?
—SA

1 solution

Hi Super_user,

Please provide more clarity on ur question.
I think ur code is not working may the response coming from server is not in valid string format abd by the way, you are not saving the data after converting it using JSON.stringify so thats causing the problem may be. Inside alert only u r converting into string but not while spilting it.

I have used the below code in my application & its working fine.

JavaScript
success: function (data) {
            debugger
	    
            var dataInStringFormat = JSON.stringify(data);//u r missing this
            var data1 = dataInStringFormat.split('*')[0];//should be a proper string b4 spilting
            var data2 = dataInStringFormat.split('*')[1];
 
            alert(data1);
            alert(data2);
        },



Please revert back with ur queries if any.
 
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