DragonWar% 2014-06-22 08:33 采纳率: 0%
浏览 50

jQuery JSONP解析错误

I'm working on a PhoneGap project that uses jQuery AJAX to get data from our online app.

Here is the code I am using:

$.ajax({
    type: 'GET',
    url: home ,
    async: false,
    dataType: "jsonp",
    jsonpCallback: 'jsonCallback',
    data: {action: 'get_survey', survey: survey_id},
    success: function (result) {

        $.mobile.loading( 'hide', {});
        display_survey(result);

    },
    error: function (request,error) {

        $.mobile.loading( 'hide', {});
        alert(error);
    }
});

Here is the data that is being returned from the server:

jsonCallback({"symptoms":{"ent":["Does not pay attention to details or makes careless mistakes wiht, for example, homework","Has difficulty keeping attention to what needs to be done","Does not seem to listen when spoken to directly","Does not follow through when given directions and fails to finish activities (not due to refusal or vailure to understand)","Has difficulty organizing tasks and activities","Avoids, dislikes, or does not want to start tasks that require ongoing mental effort","Loses things necessary for tasks or activities (toys, assignments, pencils or books","Is easily distracted by noises or other stimuli","Is forgetful in daily activities","Fidgets with hands or feet or squirms in seat","Leaves seat when remaining seated is expected","Runs about or climbs too much when remaining seated is expected","Has difficulty playing or beginning quiet play activities","Is 'on the go' or often acts if 'driven by a motor'","Talks too much","Blurts out answers before questions have been completed","Has difficulty waiting his or her turn","Interrupts or intrudes on others' conversations and\/or activities","Argues with adults","Loses temper","Actively defies or refuses to go along with adults' requets or rules","Deliberately annoys people","Blames others for his or her mistakes or misbehaviors","Is touchy or easily annoyed by others","Is angry or resentful","Is spiteful and wants to get even","Bullies, threatens, or intimidates others","Starts physical fights","Lies to get out of trouble or to avoid obligations (ie, 'cons' others)","Is truant from school (skips school) without permission","Is physically cruel to people","Has stolen things that have value","Deliberately destroys others' property","Has used a weapon that can cause serious harm (bat, knife, brick, gun)","Is physically cruel to animals","Has deliberately set fires to cause damage","Has broken into someone else's home, business or car","Has stayed out at night without permission","Has run away from home overnight","Has forced someone into sexual activity","Is fearful, anxious or worried","Is afraid to try new things for fear of making mistakes","Feels worthless or inferior","Blames self for problems, feels guilty","Feels lonely, unwanted or unloved; complains that 'no one loves him or her'","Is sad, unhappy or depressed","Is self-conscious or easily embarrrassed"]},"performance":{"ent":["Overall school performance","Reading","Writing","Mathematics","Relationship with parents","Relationship with siblings","relationship wiht peers","Participation in organized activities (eg, teams)"]}})

Right now, I am testing the app in a browser. When the PG app is called from the same server as the online app, it works fine. However, if the PG app is on a different server, I get a 'parseError' from jQuery and the error function is triggerd.

However, when I look in the console, I can see that the PG app is receiving all of the data.

Am I missing something when I set-up the JSONP call?

  • 写回答

2条回答 默认 最新

  • weixin_33736649 2014-06-22 13:29
    关注

    Your JSON is Valid. Looks like cross domain request problem. An observation from your post :

    Please remove or change

     async : false 
    

    to

     async : true
    

    Because, by default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation. Refer here

    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀