weixin_33682790 2014-06-12 06:38 采纳率: 0%
浏览 36

用jQuery发布mockjax

I have mockjax for auto complete and it is working great.I have no issue with mockjax and do not want to change it.

Here is its code

   $.mockjax({
    url: '*',
    responseTime: 2000,
    response: function (settings) {
        var query = settings.data.query,
            queryLowerCase = query.toLowerCase(),
            re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi'),
            suggestions = $.grep(countriesArray, function (country) {
                 // return country.value.toLowerCase().indexOf(queryLowerCase) === 0;
                return re.test(country.value);
            }),
            response = {
                query: query,
                suggestions: suggestions
            };

        this.responseText = JSON.stringify(response);
    }
});

Now on the same page i have to use jquery post which give me error

$.post("save.php", { id:id }, function(data) {
alert(data);
});

It qive me error "query not define"

Please teach me how to use both on one page with out disturbing other?

  • 写回答

1条回答 默认 最新

  • weixin_33722405 2014-07-11 15:33
    关注

    The object you are passing to jQuery.post does not have a query key, but you are trying to reference it in the first line of the mockjax response function: settings.data.query

    Mockjax just passes whatever data you try to post with jQuery to the callback you specify.

    See how this feature works in a simple example: http://jsfiddle.net/gabor_nagy/N4x2Z/

    评论

报告相同问题?