I have a script file that makes a call to JSON API, and I need to send the current login username as part of the call. I tried the following :-
$(document).ready(function () {
var name = prompt("Please enter your packageid", "test");
var fullurl = 'http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=' + HttpContext.Current.User.Identity.Name + 'packageId=' + name;
$.ajax({
type: "GET",
url: fullurl,
dataType: "JSONP",
success: function (result) {
//code goes here
But it will raise the following error:- ‘HttpContext’ is undefined
Your script is looking for a Javascript variable called
HttpContextYour code should bein Razor
so the javascript becomes
You’re also missing and
&between the user name and packageId if you intended for them to be separate variablesEdit: based on your comment and this being inside of a js file (which I guess I missed in the OP)
Two options:
Page
JS file
Option Two is to not include the username at all and just get it from the Action. This is only an option if the page you’re posting to is on the same app