从下面的代码中,我收到parseerror错误,错误为:函数(jqXHR,异常) 它总是给我这个错误,而在响应文本中我得到了我需要的所有数据。 请为我提供解决此问题的方法,并通过成功获得所有详细信息:功能
这是我的脚本代码
function Create() {
var objIntegration = {
ProductCode: $('#ProductCode').val(),
environmentType: ($("input[type=radio]:checked").val())
};
alert("Your are select product Code is " + objIntegration.ProductCode + " on Environment Type of " + objIntegration.environmentType);
$.ajax({
url: "/Home/Create",
type: "POST",
cache: false,
//async: true,
contentType: "application/json; charset=utf-8",
data: JSON.stringify(objIntegration),
dataType: "Json",
success: function (data) {
alert("Hi from Success.");
if (data.status == "Success") {
alert("From Success your choose");
}
},
error: function (jqXHR, exception) {
alert("Hi from Error");
}
});
这是我的控制器代码
public ActionResult Create(Integration objIntegration)
{
string product = objIntegration.ProductCode;
string type = objIntegration.environmentType;
string jsonrequest = string.Empty;
Uri uri = null;
string ErrorMsg = string.Empty;
string ResponseXML = string.Empty;
string Premium = string.Empty;
string No = string.Empty;
string PropNo = string.Empty;
string ResponseTime = string.Empty;
try
{
string tmp = string.Empty;
string authenticationKey = GetAuthenticationKey(objIntegration.environmentType);
XmlDocument InputXML = new XmlDocument();
InputXML.Load(@"D:\Int Kit\4102\4102.xml");
string xmlcontents = InputXML.InnerXml;
string inputxml = xmlcontents.ToString();
string Code = objIntegration.Code;
if (objIntegration.environmentType == "AAA")
{
jsonrequest = @"{
""Input"":
{
""UserID"": ""AAA"",
""Password"": ""password@1"",
""UserRole"": ""ADMIN"",
""Code"": ""1"",
""ModeOfOperation"": ""NEW"",
""AuthenticateKey"": ""0"",
""InputXML"": ""1"",
""GenerationMode"":""1""
}
}";
uri = new Uri("https://Localhost:........");
}
else
{
jsonrequest = @"{
""Input"":
{
""UserID"": ""test"",
""Password"": ""password1"",
""UserRole"": ""ADMIN"",
""Code"": ""1"",
""ModeOfOperation"": ""OLD"",
""AuthenticateKey"": ""0"",
""InputXML"": ""1"",
""GenerationMode"":""1""
}
}";
}
dynamic rss = JObject.Parse(jsonrequest);
JObject tempUserData = (JObject)rss.SelectToken("Input");
tempUserData["AuthenticateKey"] = authenticationKey;
tempUserData["ProductCode"] = Code;
tempUserData["InputXML"] = inputxml;
string data1 = rss.ToString();
if (uri.Scheme == Uri.UriSchemeHttps)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.KeepAlive = false;
request.ContentLength = data1.Length;
request.ContentType = "application/json; charset=utf-8";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data1);
writer.Close();
string startTime = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
tmp = reader.ReadToEnd();
string endTime = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
DateTime startDate = DateTime.ParseExact(startTime, "MM/dd/yyyy HH:mm:ss", null);
DateTime endate = DateTime.ParseExact(endTime, "MM/dd/yyyy HH:mm:ss", null);
TimeSpan ts = endate.Subtract(startDate);
int second = (int)ts.Seconds;
Response.Write(second.ToString());
XMLResponse objXMLResponse = JsonConvert.DeserializeObject<XMLResponse>(tmp);
string errorText = objXMLResponse.SaveResult.ErrorText;
string errorCode = objXMLResponse.SaveResult.ErrorCode;
string outputXML = objXMLResponse.SaveResult.OutputXML;
double netPremium = objXMLResponse.SaveResult.NetPremium;
double serviceTax = objXMLResponse.SaveResult.ServiceTax;
double totalPremium = objXMLResponse.SaveResult.TotalPremium;
string proposalNumber = objXMLResponse.SaveResult.ProposalNumber;
string quotationNumber = objXMLResponse.SaveResult.QuotationNumber;
ErrorMsg = errorText;
ResponseXML = outputXML;
Premium = totalPremium.ToString();
QuotationNo = quotationNumber;
ProposalNo = proposalNumber;
ResponseTime = second.ToString();
}
}
catch (Exception ex)
{
ErrorMsg = ex.ToString();
}
return Json(new
{
status = "Success",
jsproduct = product,
jstype = type,
jsQuotationNo = QuotationNo,
}, JsonRequestBehavior.AllowGet);
// return View();
}