weixin_33709364 2014-07-25 11:29 采纳率: 0%
浏览 29

JSONP Ajax语法

I am trying to alert the visitor of my webpage with a country code provided by a JSONP endpoint. However, I cannot seem to get this working! And all the answers on the web seem confusing!

The following is returned from the endpoint:

{
    "pcCartCt": 0,
    "pcCountryCode": "au",
    "pcCountrySite": "WWW",
    "pcExpDomCt": 0,
    "pcFirstName": "",
    "pcIsCdc": false,
    "pcIsDiscount": false,
    "pcIsGdEmployee": false,
    "pcIsTrusted": false,
    "pcLanguageCookie": "en-us",
    "pcModalData": "",
    "pcRepEmail": "",
    "pcRepExt": "",
    "pcRepName": "",
    "pcSelectedCurrFullDesc": "United States Dollar $ (Transactional)",
    "pcSelectedCurrType": "USD",
    "pcSetLanguageLogo": true,
    "pcShopperId": ""
}

For it to work, I first need to specify a prog_id of "myprogid" and a callback function. In the callback, I need an alert message containing pcCountryCode.

How do I do this?

  • 写回答

2条回答 默认 最新

  • csdnceshi62 2014-07-25 11:40
    关注

    The endpoint should return:

    myprogid({
        "pcCartCt": 0,
        "pcCountryCode": "au",
        "pcCountrySite": "WWW",
        "pcExpDomCt": 0,
        "pcFirstName": "",
        "pcIsCdc": false,
        "pcIsDiscount": false,
        "pcIsGdEmployee": false,
        "pcIsTrusted": false,
        "pcLanguageCookie": "en-us",
        "pcModalData": "",
        "pcRepEmail": "",
        "pcRepExt": "",
        "pcRepName": "",
        "pcSelectedCurrFullDesc": "United States Dollar $ (Transactional)",
        "pcSelectedCurrType": "USD",
        "pcSetLanguageLogo": true,
        "pcShopperId": ""
    });
    

    I don't understand your question about parsing multiple parameters. JSONP just expects one special parameter: callback=myprogid. This parameter should be used as the name of the function at the beginning of the response.

    评论

报告相同问题?