The first snippet is bad syntax and shouldn't be used, you get the alert because it is called immediately, not on success.
There are only two reasons for you to not get the alert with the 2nd snippet.
Most likely you are confusing JSONP with JSON, so i'll give you an example of each. First is json:
and this is JSONP
somecallbackname will be supplied by jQuery, you'll have to get the value of the callback get parameter and use it to generate the JSONP accordingly.
The alert you're getting from your first code snippet is misleading.
alert("Success") is assigned to the
success property your actually immediately calling it.
You're second approach is the one you want.