2016-06-01 11 views
0

Mit Bezug auf this question, das ist, wie dies ohne eine Funktion gelöst. Jetzt habe ich eine Funktion, und ich versuche, in JavaScript aufzurufen und auch versuchen, diese Daten in alert Box anrufen, aber die alert Box füllt nicht. Mein Code ist dies:Daten in Alarmbox durch Funktion 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); 
 
    }, 
 
    error: function() { 
 
     debugger; 
 
     alert(data1); 
 
     alert(data2); 
 
    } 
 
    }); 
 
}); 
 

 
function Loadchart() { 
 
    $('#submitchart').click(); 
 
};
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
 

 
<form id="form1" runat="server"> 
 
    <asp:DropDownList ID="yearValue" runat="server" AutoPostBack="True" ViewStateMode="Enabled"></asp:DropDownList> 
 
    <button id="submitchart" runat="server">Show Chart</button> 
 
    <div id="container" style="width: 100%; height: 400px;"></div> 
 
</form>

+0

Browser Anhalten bei Debugger ist? – brk

+0

entfernen JSON.stringify – madalinivascu

+0

können Sie das Format der Antwort angeben? – madalinivascu

Antwort

0
<head runat="server"> 
    <title></title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <select id="yearValue"><option>1920</option></select> 
     <button id="submitchart" runat="server" type="button">Show Chart</button> 
     <div id="container" style="width: 100%; height: 400px;"></div> 
    </form> 
</body> 

<script type="text/javascript"> 
    $('#submitchart').click(function() { 
     //alert("i"); 
     var webmethod = 'test.php'; 
     $.ajax({ 
      type: 'POST', 
      url: webmethod , 
      data: JSON.stringify({ 
       yearP: $('#yearValue').val() 
      }), 
      contentType: 'application/json;charset=utf-8', 
      dataType: 'json', 
      success: function(response) { 
       alert('working'); 

      }, 
      error: function() { 
       alert('error'); 
      }  
     }); 
    }); 

    function Loadchart() { 
     $('#submitchart').click(); 
    }; 
</script> 

Above Code funktioniert. Überprüfen und aktualisieren Sie mit Ihrem. Stellen Sie sicher, dass die Schaltfläche "Schaltfläche" gedrückt wird

0

Wickeln Sie Ihren Code in einem Dokument bereit Anweisung entfernen JSON.stringify

<head runat="server"> 
    <title></title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <select id="yearValue"><option>1920</option></select> 
     <button id="submitchart" runat="server" type="button">Show Chart</button> 
     <div id="container" style="width: 100%; height: 400px;"></div> 
    </form> 
</body> 

<script type="text/javascript"> 
    $(function(){ 
    $('#submitchart').click(function (e) { 
     e.preventDefault(); 
     var webmethod = 'test.php'; 
     $.ajax({ 
      type: 'POST', 
      url: webmethod , 
      data: JSON.stringify({ 
       yearP: $('#yearValue').val() 
      }), 
      contentType: 'application/json;charset=utf-8', 
      dataType: 'json', 
      success: function(response) { 
       alert('working'); 

      }, 
      error: function() { 
       alert('error'); 
      }  
     }); 
    }).trigger('click'); 
}); 
</script> 
Verwandte Themen