I want to call the following webservice as mentioend on this link
http://dev.joget.org/community/display/KB/JSON+API#JSONAPI-web%2Fjson%2Fworkflow%2Fprocess%2Flist
So inside my asp.net mvc view i wrote the folloiwng:-
<script type="text/javascript">
$(document).ready(function () {
// Send an AJAX request
$.getJSON("http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin",
function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, val) {
// Format the text to display.
var str = val.id + ': $' + val.packageName;
// Add a list item for the product.
$('<li/>', { text: str })
.appendTo($('#products'));
});
});
});
</script>
<h1>The Processes are</h1>
<ul id="products"/
If you are using the default MVC template views, the JavaScript should be rendered in the @section "scripts". Using the following in the default MVC4 template in the Index.cshtml file I was able to get the ajax call to work:
@{
ViewBag.Title = "Home Page";
}
@section featured {
<section class="featured">
<h1>The Processes are</h1>
<ul id="products" />
</section>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(document).ready(function () {
// Send an AJAX request
$.getJSON("/api/WebApiTest/test",
function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, val) {
// Format the text to display.
var str = val.id + ': $' + val.packageName;
// Add a list item for the product.
$('<li/>', { text: str })
.appendTo($('#products'));
});
});
});
</script>
}
Darrell Norton, MVP
Darrell Norton's Blog Please click "Mark as Answer" if this helped you.
@section scripts {
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
$(document).ready(function () {
// Send an AJAX request
$.getJSON("http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin",
function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, val) {
// Format the text to display.
var str = val.id + ': $' + val.packageName;
// Add a list item for the product.
$('<li/>', { text: str })
.appendTo($('#products'));
});
});
});
</script>
i tried writting the javascript directly at the view in an asp.net mvc and using a simpler API that retruned only two parameters ,, and the problem is still happening ..
@{
ViewBag.Title = "Home Page";
}
<ul id="products"/>
<h2>@ViewBag.Message</h2>
<p>
To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
<h1>The Processes are </h1>
<script type="text/javascript">
$(document).ready(function () {
// Send an AJAX request
$.getJSON("http://localhost:8080/jw/web/json/workflow/package/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin",
function (data) {
// On success, 'data' contains a list of products.
$.each(data, function (key, val) {
// Format the text to display.
var str = val.packageId + ': $' + val.packageName;
// Add a list item for the product.
$('<li/>', { text: str })
.appendTo($('#products'));
});
});
});
</script>
i have noted something strange , if i add the following alert("will it reach here"); after the $.getJSON then the alert will not be shown on run time, while if insert it at the begining of the script the alert will be shown.
$.ajax({
type: "GET",
url: "http://localhost:8080/jw/web/json/workflow/package/list?loginAs=admin",
dataType: "JSONP",
contentType: "application/json; charset=utf-8",
success: function (data) {
$.each(data, function (key, val) {
// Format the text to display.
var str = val.packageId + ': $ ' + val.packageName;
// Add a list item for the product.
$('<li/>', { text: str })
.appendTo($('#products'));
});
}});
});
but the result of the web service call is returned as
undefined: $ undefined
instead of being something similat to
{"activityId":"","processId":"289_process1"}
So what is the problem that is preventing my code from displaying the right data ?
johnjohn1231...
Participant
922 Points
871 Posts
Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:05 AM|LINK
I want to call the following webservice as mentioend on this link http://dev.joget.org/community/display/KB/JSON+API#JSONAPI-web%2Fjson%2Fworkflow%2Fprocess%2Flist
So inside my asp.net mvc view i wrote the folloiwng:-
<script type="text/javascript"> $(document).ready(function () { // Send an AJAX request $.getJSON("http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin", function (data) { // On success, 'data' contains a list of products. $.each(data, function (key, val) { // Format the text to display. var str = val.id + ': $' + val.packageName; // Add a list item for the product. $('<li/>', { text: str }) .appendTo($('#products')); }); }); }); </script> <h1>The Processes are</h1> <ul id="products"/But when i run the above web page no processes will be displayed under the <h1>The Processes are </h1> , while if i type the following http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin directly on the address-bar of my browser then all the processes will be displayed. so what might be going wrong ?
BR
DarrellNorto...
All-Star
86773 Points
9643 Posts
Moderator
MVP
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:24 AM|LINK
If you are using the default MVC template views, the JavaScript should be rendered in the @section "scripts". Using the following in the default MVC4 template in the Index.cshtml file I was able to get the ajax call to work:
@{ ViewBag.Title = "Home Page"; } @section featured { <section class="featured"> <h1>The Processes are</h1> <ul id="products" /> </section> } @section Scripts { @Scripts.Render("~/bundles/jqueryval") <script type="text/javascript"> $(document).ready(function () { // Send an AJAX request $.getJSON("/api/WebApiTest/test", function (data) { // On success, 'data' contains a list of products. $.each(data, function (key, val) { // Format the text to display. var str = val.id + ': $' + val.packageName; // Add a list item for the product. $('<li/>', { text: str }) .appendTo($('#products')); }); }); }); </script> }Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:32 AM|LINK
thanks for the reply, i tried the belwo code:-
@section scripts { @Scripts.Render("~/bundles/jqueryval") <script type="text/javascript"> $(document).ready(function () { // Send an AJAX request $.getJSON("http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin", function (data) { // On success, 'data' contains a list of products. $.each(data, function (key, val) { // Format the text to display. var str = val.id + ': $' + val.packageName; // Add a list item for the product. $('<li/>', { text: str }) .appendTo($('#products')); }); }); }); </script>but still nothing is b3eing displayed.
BR
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:40 AM|LINK
i tried writting the javascript directly at the view in an asp.net mvc and using a simpler API that retruned only two parameters ,, and the problem is still happening ..
@{ ViewBag.Title = "Home Page"; } <ul id="products"/> <h2>@ViewBag.Message</h2> <p> To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>. </p> <h1>The Processes are </h1> <script type="text/javascript"> $(document).ready(function () { // Send an AJAX request $.getJSON("http://localhost:8080/jw/web/json/workflow/package/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=admin", function (data) { // On success, 'data' contains a list of products. $.each(data, function (key, val) { // Format the text to display. var str = val.packageId + ': $' + val.packageName; // Add a list item for the product. $('<li/>', { text: str }) .appendTo($('#products')); }); }); }); </script>amitpatel.it
Star
7956 Points
1865 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:40 AM|LINK
Try with below code...
var url = '@Url.Content("~/your related virstual path")'; $.ajaxSetup ( { cache: false } ); $.getJSON(url, { parameter 1 : 1, parameter 2: 0 }, function (data) { alert(data.name); });MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 09:42 AM|LINK
thanks ,, but can u explain your code more .
Best Regards
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 11:28 AM|LINK
i have noted something strange , if i add the following alert("will it reach here"); after the $.getJSON then the alert will not be shown on run time, while if insert it at the begining of the script the alert will be shown.
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 09, 2012 02:23 PM|LINK
i updated my JavaScript to the following:-
$.ajax({ type: "GET", url: "http://localhost:8080/jw/web/json/workflow/package/list?loginAs=admin", dataType: "JSONP", contentType: "application/json; charset=utf-8", success: function (data) { $.each(data, function (key, val) { // Format the text to display. var str = val.packageId + ': $ ' + val.packageName; // Add a list item for the product. $('<li/>', { text: str }) .appendTo($('#products')); }); }}); });but the result of the web service call is returned as
instead of being something similat to
{"activityId":"","processId":"289_process1"}So what is the problem that is preventing my code from displaying the right data ?
johnjohn1231...
Participant
922 Points
871 Posts
Re: Fail to call a Json web service inside my asp.net mvc 4 application
Oct 10, 2012 11:49 AM|LINK
// code goes here function (result) { $.each(result.data, function (key, val) { // code goes here