0

If I hard-code this, everything is as expected:

var bytes = Utf8.parse('myString');

But this does return the same string as above.

var temp = String(getMyString());
var bytes = Utf8.parse(temp)

Here is my ajax call that calls the next code block.

    function getMyString() {
        $.ajax({
            dataType: 'json',
            type: 'post',
            contentType: 'application/json',
            url: '/Controller/GetString',
            success: function (response) {
                var obj = JSON.parse(response.Success);
                return obj;
            }
        });
    }

My Controller Calls the Next Code Block.

    public JsonResult GetString()
    {
        var s = myClass.GetMyString();
        return Json(new { Success = s });
    }

In a static class

public static string GetMyString()
{            
    return "myString";
}

The End result is a thrown exception because the Byte array is off, because the input string is somehow not the same. I thought a async controller might be to blame, so that is my next attempt.

user1307149
  • 1,427
  • 2
  • 16
  • 30
  • What are you using `JSON.parse`? Should be just `var obj = response.Success` –  Jan 17 '18 at 23:22
  • I tried that and it is producing the same result. Called response.Success.toString(), tried '' + response.Success. – user1307149 Jan 17 '18 at 23:23
  • 1
    What result? You have not explained what the result is in either case. –  Jan 17 '18 at 23:23
  • Byte array is not the same from the inputs. I edited my post. – user1307149 Jan 17 '18 at 23:26
  • And what is `Utf8.parse()`? What plugin are you using? –  Jan 17 '18 at 23:29
  • Your `temp` is empty, since `getMyString()` doesn't return anything. Once again this is a ... –  Jan 17 '18 at 23:31
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) –  Jan 17 '18 at 23:31

0 Answers0