0

Thanks to all who was trying to help me with WP8 and AJAX.

Problem in a few words, here is my code in WP8+Phonegap:

document.addEventListener('deviceready', function () {
            jQuery.support.cors = true;
            $.mobile.allowCrossDomainPages = true;
            $.Mustache.load("www/about.txt");
        }, false);

In jquery.mustache.js .load():

function load(url, onComplete) {
    return $.ajax({
            url: url,
            dataType: options.externalTemplateDataType
        }).done(function (templates) {
            $(templates).filter('script').each(function (i, el) {
                add(el.id, $(el).html());
            });

            if ($.isFunction(onComplete)) {
                onComplete();
            }
        });
}

When gets callback it goes to function Add.

It all works on iOS, Android and WP8.

But on WP7.5 it doesn't work. How to fix it?

4

2 回答 2

0

Have you try to put a complete function like this

$.support.cors = true;
$.ajax({
    type: "POST",
    dataType: "HTTP/1.1",
    url: 'yoururl',
    dataType: options.externalTemplateDataType,
    cache: 'false',
    async: false,
    error: function (data) {
        console.log(data);
        console.log("error");
    },
    complete: onComplete(data)
});

And see what is on data

于 2013-06-11T12:27:27.713 回答
0

Answer was simple, in WP8/Phonegap application you must specify full path to a resource:

$.Mustache.load("www/about.txt");

In WP7/Phonegap application you must NOT specify full path:

$.Mustache.load("about.txt");

Hope it will help someone.

于 2013-06-12T05:52:48.307 回答