if i have a href getJSON is working fine as expected (getting alert message box) but where as if i use input button then it does not work (no alert message), below is my example using both a href and input button, i open the firebug and i dont see that any data in response.
working
<a href="'http://host/Myservice.svc/GetCustomerBy?GetCustomerBy?GetCustomerBy=?">GetCustomerBy</a>
$(function () {
$('a').click(function () {
$.getJSON(this.href, { id: '2' }, function (customer) {
alert(customer.Name);
alert(customer.Address);
});
return false;
});
});
not working
<input type="button" id="driver" value="Load Data" />
$("#driver").click(function (event) {
$.getJSON('http://host/Myservice.svc/GetCustomerBy?GetCustomerBy=?', { id: '2' }, function (customer) {
alert(customer.Address);
alert(customer.Name);
});
});
Try this:
Notice that the call is wrapped in a $(document).ready and that you don’t need to
return false. Also no need to use theeventargument to the anonymous callback.Also comparing your href address is not the same as the one you are using in the button. In the href you have:
whereas in the button you have:
which is not the same. So make sure you use the correct address whatever this address is. FireBug would have helped you in this case.