Skip to content

Instantly share code, notes, and snippets.

@PaulSorensen
Created September 26, 2013 09:44
Show Gist options
  • Save PaulSorensen/6712034 to your computer and use it in GitHub Desktop.
Save PaulSorensen/6712034 to your computer and use it in GitHub Desktop.
egeek.dk - WCF return JSON, AJAX-enabled WCF Service in less than 3 minutes
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
var personNameVar = "Paul";
var dataIn = '{' + '"personName":"' + personNameVar + '"}';
$.ajax({
url: "/Service1.svc/HelloWorld",
type: "POST",
contentType: "application/json; charset=utf-8",
data: dataIn,
dataType: "json",
success: function (data) {
var object = JSON.parse(data.d);
if (object.Error == '') {
//Alert the persons name
alert(object.Response);
}
},
error: function (error) {
alert("Error: " + error.Error);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment