Code: Select all
<html>
<body>
<!-- Javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("#btn392").click(function()
{
var url = "URL of the server";
var success = function(data)
{
var html = [];
/* parse JSON */
data = $.parseJSON(data);
/* loop through array */
$.each(data, function(index, d)
{
html.push("firstname : ", d.firstname);
});
$("#div391").html(html.join('')).css("background-color", "red");
};
$.ajax(
{
type: 'GET',
url: url,
username:"username",
password:"password",
dataType: "jsonp",
crossDomain: true,
cache:false,
contentType:'application/json; charset=utf-8',
success: success,
error:function(jqXHR, textStatus, errorThrown)
{
alert(errorThrown);
},
complete: function(requestState)
{
alert("Working");
}
});
});
});
</script>
<!-- HTML -->
<div id="example-section39">
<div>Get data with JSONP</div>
<div id="div391"></div><br />
<button id="btn392" type="button">Submit</button>
</div>
</body>
</html>
Can anyone please help me out on this issue?