JQUERY函数在返回JSON数据后停止执行
我试图运行这个函数来获取JSON数据并绘制图表。我已经得到了JSON,但是在成功之后:AJAX调用我插入了一个警报,但不知怎么的没有被命中 谁能告诉我哪里出了问题 这是我的JSONJQUERY函数在返回JSON数据后停止执行,jquery,html,ajax,json,Jquery,Html,Ajax,Json,我试图运行这个函数来获取JSON数据并绘制图表。我已经得到了JSON,但是在成功之后:AJAX调用我插入了一个警报,但不知怎么的没有被命中 谁能告诉我哪里出了问题 这是我的JSON { "t": "radioiodine", "y": 50, "x": "2014-04-04" }{ "t": "radioiodine", "y": 50, "x": "2013-06-09" }{ "t": "radioiodine", "y":
{
"t": "radioiodine",
"y": 50,
"x": "2014-04-04"
}{
"t": "radioiodine",
"y": 50,
"x": "2013-06-09"
}{
"t": "radioiodine",
"y": 100,
"x": "2012-03-05"
}{
"t": "radioiodine",
"y": 200,
"x": "2008-05-04"
}{
"t": "radioiodine",
"y": 100,
"x": "2006-02-17"
}{
"t": "radioiodine",
"y": 50,
"x": "2002-03-31"
}{
"t": "radioiodine",
"y": 100,
"x": "2001-02-23"
}{
"t": "radioiodine",
"y": 50,
"x": "2000-12-13"
}{
"t": "radioiodine",
"y": 100,
"x": "2000-04-06"
}
这是我的密码
$(document).ready(function(){
$("#find").click(function(e){
e.preventDefault();
$.ajax({
// the URL for the request
url: "getrad.php",
// the data to send (will be converted to a query string)
data: {pnhsno: $('#search').val()},
// whether this is a POST or GET request
type: "GET",
// the type of data we expect back
dataType : "json",
// code to run if the request succeeds;
// the response is passed to the function
success: function(json){
alert("start");
if(json.length !=0 ){
var dataPoints = json.map(function (p) {
p.x = new Date(p.x);
return p;
});
//var dp1 = [];
//var lt1;
//for(var i=0; i<dataPoints.length; i++){
// if(dataPoints[i].t =="radioiodine"){
// lt1 =dataPoints[i].t;
// dp1.push({x:dataPoints[i].x, y:dataPoints[i].y})}
//}
// $("#radioiodine").CanvasJSChart({ //Pass chart options
// title:{text:"Radioiodine Dosage"},
// zoomEnabled: true,
// panEnabled: true,
// axisX:{valueFormatString:"DD-MM-YYYY",labelAngle:-45},
//
// data: [
// {
// type: "column",
// legendText:lt1,
// showInLegend:true,
// dataPoints:dp1
// }]});
}//if
//else{ $("#radioiodine").html("No Data For Radioiodine Found");}
}//json
});
});
});
$(文档).ready(函数(){
$(“#查找”)。单击(函数(e){
e、 预防默认值();
$.ajax({
//请求的URL
url:“getrad.php”,
//要发送的数据(将转换为查询字符串)
数据:{pnhsno:$('#search').val()},
//这是一个POST还是GET请求
键入:“获取”,
//我们期望返回的数据类型
数据类型:“json”,
//请求成功时要运行的代码;
//响应被传递给函数
成功:函数(json){
警报(“启动”);
if(json.length!=0){
var dataPoints=json.map(函数(p){
p、 x=新日期(p.x);
返回p;
});
//var dp1=[];
//var lt1;
//对于(var i=0;i,因为您提供的json格式无效。有效的json如下所示:
[{
"t": "radioiodine",
"y": 50,
"x": "2014-04-04"
},{
"t": "radioiodine",
"y": 50,
"x": "2013-06-09"
},{
"t": "radioiodine",
"y": 100,
"x": "2012-03-05"
},{
"t": "radioiodine",
"y": 200,
"x": "2008-05-04"
},{
"t": "radioiodine",
"y": 100,
"x": "2006-02-17"
},{
"t": "radioiodine",
"y": 50,
"x": "2002-03-31"
},{
"t": "radioiodine",
"y": 100,
"x": "2001-02-23"
},{
"t": "radioiodine",
"y": 50,
"x": "2000-12-13"
},{
"t": "radioiodine",
"y": 100,
"x": "2000-04-06"
}]
最有可能的是,success
之所以没有成功,是因为您的ajax调用从未成功。还值得一提的是,错误处理程序会有帮助。如果您是对的,我会检查它。是的,它正在工作。谢谢