websss
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
However I've no idea how to convert to returned string
to the JS object: imageDataArray
In the othe question i used @HTML.RAW, which works great and i can then access the data like
How would i do this in Js/Jquery?
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;
}
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........ ]]
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]
to get the value at that positionHow would i do this in Js/Jquery?
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)
However after updating the object, it looks like this, and it doesn't work with the rest of the code
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)
However after updating the object, it looks like this, and it doesn't work with the rest of the code
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
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
And in your AJAX Callback
Just for giggles try this
imageArray = JSON.parse(response.DataArray);
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>
And in your AJAX Callback
$('#result').value = response.DataArray;
Please post the HomeController/CameraChang e method so we can see what it returns?
ASKER
This is the code
the bit in question is in another method and saves this as a string
[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);
}
the bit in question is in another method and saves this as a string
pd.DataArray = JsonConvert.SerializeObject(temperat ureData);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, JSON.parse() fixed it
You are welcome.
The returned data is an array of arrays.
Open in new window
Will give you the first value in the first array