Javascript返回参数不起作用。 [英] Javascript return parameter not working.
问题描述
我有一个返回数据的javascript函数。
函数是
function getEventData(){
return {events:[{ id: 2 , start: new 日期( 2013 , 4 , 24 , 12 , 0 ), end: new 日期(< span class =code-digit> 2013 , 4 , 24 , 11 , 0 ), title : test}]};
}
当我编写如上所述的函数(带有核心数据)时它正常工作
当我使用某个变量时,它不起作用..比如
function getEventData(){
$ .ajax({
url: ../ PHP / PhpAction.php?f = fetchCalendarEvent,
async: false ,
成功:功能(数据){
result = data;
}
});
alert(result);
返回结果;
}
但在警报中,相同的数据即将到来。如果我只是复制警报数据和粘贴它的工作正常
任何人都可以帮助我....
< blockquote> .ajax({
url: ../ PHP / PhpAction.php?f = fetchCalendarEvent ,
异步: false ,
成功:功能(数据){
result = data;
}
});
alert(result);
返回结果;
}
但在警报中,相同的数据即将到来。如果我只是复制警报数据和粘贴它的工作正常
任何身体都可以帮助我....
Hello Amit,
尝试在ajax调用中添加dataType:json。它应该返回JSON对象而不是字符串。您修改后的代码看起来如下所示。function getEventData(){
result = ;
.ajax({
url: ../ PHP / PhpAction.php?f = fetchCalendarEvent,
dataType: < span class =code-string> json,
async: false ,
成功: function (data){
result = data;
}
});
alert(result);
返回结果;
}
问候,
I have a javascript function which return data.
The function is
function getEventData() {
return { events: [{ "id": 2, "start": new Date(2013, 4, 24, 12, 0), "end": new Date(2013, 4, 24, 11, 0), "title": "test"}] };
}
it''s working fine when I write the function like above (with hardcore data)
When I use some variable then it''s not working ..like
function getEventData() {
$.ajax({
url: "../PHP/PhpAction.php?f=fetchCalendarEvent",
async: false,
success: function (data) {
result = data;
}
});
alert(result);
return result;
}
But in the Alert the same data is coming.If I just copy the alert data and paste in return it''s working fine
Can any body help me please....
.ajax({ url: "../PHP/PhpAction.php?f=fetchCalendarEvent", async: false, success: function (data) { result = data; } }); alert(result); return result; }
But in the Alert the same data is coming.If I just copy the alert data and paste in return it''s working fine
Can any body help me please....
Hello Amit,
Try adding dataType:"json" in the ajax call. It should return the JSON object instead of a string. Your modified code will look something like the one shown below.function getEventData() { result = "";
.ajax({ url: "../PHP/PhpAction.php?f=fetchCalendarEvent", dataType: "json", async: false, success: function (data) { result = data; } }); alert(result); return result; }
Regards,
这篇关于Javascript返回参数不起作用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!