I have this situation: in MVC View javascript function I call controller action and get some xml data string and then I call another controller action where I make new object and call new view. I always get error message: Error while request "undefined" : TextStatus : "parsererror" ErrorThrown : "SyntaxError: JSON parse: unexpected character at line 1 column 1 on the JSON data"
I don't have any idea why is this happening. If I direct call second controller action with hardcoded xml inthere I get correct result - new view. How can I call controller action from javascript function in view without refreshing view?
This is my code:
javascript function in view CompleteFrameBrand:
function order(model) {
$.p({
url: '@Url.Action("CompleteFrameBrandDetails", "PacCompleteFrame")',
data: { item: model },
success: function (result) {
if (result.Success) {
$.p({
url: '@Url.Action("GlassCompleteFrame", "PacModule")',
data: JSON.stringify({ b2bXml: result.Data }),
success: function (result) {
return;
}
});
} else {
$.alert({
message: 'error while trying to load xml details'
});
}
}
});
CompleteFrameController::CompleteFrameBrandDetails(string item)
public ActionResult CompleteFrameBrandDetails(string item)
{
var customerNumber = _workContext.SelectedCustomerNumber;
var employeeId = _workContext.CurrentCustomer.Ll3Id;
string b2bxml = _completeFrameService.GetCFB2BXML(employeeId, customerNumber, item, _workContext.WorkingLanguage.LanguageCulture.Substring(3));
return new JsonResult()
{
Data = new
{
Success = true,
Data = b2bxml
}
};
}
PacModuleController::GlassCompleteFrame:
public ActionResult GlassCompleteFrame(string b2bXml)
{
PacModuleModel model = new PacModuleModel();
model.CustomerNumber = _workContext.SelectedCustomerNumber;
model.Language = _workContext.WorkingLanguage.UniqueSeoCode;
model.Comission = "";
model.GlassXml = b2bXml.Replace("\"", "\\\"");
model.Price = Convert.ToDouble(p, System.Globalization.CultureInfo.InvariantCulture);
model.ReadOnly = false;
return View("Glass", model);
}
success
handler does nothing. – DavidViewResult
, not aJSONResult
like your first request. What is thisGlass
view returning? I'm guessing it isn't JSON or XML. – Mister Epic