Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

html.raw in jquery?

Following on from this question
https://www.experts-exchange.com/questions/29143196/Float-array-in-c-when-passed-to-JS-it's-in-wrong-order.html?headerLink=workspace_answered_questions

I now need to
call the following

 $.ajax({
                type: "POST",
                url: "@Url.Action("CameraChange", "Home")",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                   imageDataArray = response.DataArray;
                }

Open in new window



However I've no idea how to convert to returned string
[[273.7,273.8,273.8,274.6,274.6,274,274,274.3,274........ ]]

Open in new window


to the JS object: imageDataArray

In the othe question i used @HTML.RAW, which works great and i can then access the data like
imageDataArray[x][y]

Open in new window

to get the value at that position

How would i do this in Js/Jquery?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Excatly the same way.

The returned data is an array of arrays.
imageDataArray[0][0]

Open in new window

Will give you the first value in the first array
Avatar of websss

ASKER

I puit an alert on that code, Sometimes it seems to work, other times it just returns [

But either way, its not updating the object correctly, it doesn't seem to be an array or work with the rest of the code

this is what i see from HTML RAW, and it works fine (from initial question, this works great now)
User generated image
However after updating the object, it looks like this, and it doesn't work with the rest of the code
User generated image
It might be that it needs to be parse again - not sure why it would as you have specified dataType: json in your AJAX options.

Just for giggles try this

imageArray = JSON.parse(response.DataArray);

Open in new window


And then see what that gives you.

Failing that can you post a text file or similar with the results of the AJAX response.

You can get it like this

<textarea id="result"></textarea>

Open in new window


And in your AJAX Callback
$('#result').value = response.DataArray;

Open in new window

Please post the HomeController/CameraChange method so we can see what it returns?
Avatar of websss

ASKER

This is the code
  [HttpPost]
        public JsonResult CameraChange(string cameraId)
        {

       
            camera = process.GetCamByCamId(cameraId);
          

            var imageData = process.Process_Image_Temp_Files_OnLoad(camera).FirstOrDefault();




            return Json(imageData, JsonRequestBehavior.AllowGet);
        }

Open in new window


the bit in question is in another method and saves this as a string
pd.DataArray = JsonConvert.SerializeObject(temperatureData);
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of websss

ASKER

Thanks, JSON.parse() fixed it
You are welcome.