happyZZR1400
happyZZR1400

Reputation: 2415

how to get rid of strange unexplained extra parameter inside request url

I'm making little application for checking requests. My application suppose to read parameters from xml

here is my code:

var JsonView = Backbone.View.extend({

    template: _.template($('#json-view').html()),
    invokeService: function () {

        var _this = this;

        //loading animation
        $.mobile.loading('show', {
            text: 'request sended',
            textVisible: true,
            theme: 'e',
            textonly: false
        });


        _this.prepareParams();

        console.log('params-'+ _this.params);  // params-null
        console.log('url-'+ _this.url);   //  url-/api/wines

        $.ajax({
            type: _this.model.get('action'), //GET or POST or PUT or DELETE verb
            timeout: 2000,
            cache: false,
            url: _this.url,
            data: _this.params,
            contentType: 'application/json; charset=utf-8', // content type sent to server
            dataType: 'json', //Expected data format from server
            processdata: _this.processdata, //True or False
            success: function (data) {//On Successfull service call
                _this.displayJson(data);
            },
            error: function (data, status, error) {
                _this.displayJson({ error: data });
            },
            complete: function (msg) {
                $.mobile.loading('hide');
                _this.$el.trigger('expand');

            }
        })

    },
    prepareParams: function () {
        this.url = this.model.get('path');
        this.processdata = (this.model.get('action') == 'GET');

        //build data of the request from "params":

        this.params = {};

        var beforeparams=[],afterparams='';

        _.each(this.model.get('params').models, function (param) {

            if (param.get('placein')) {
                switch(param.get('placein')){
                   case 'before':
                      beforeparams.push( param.get('defaultValue'));
                      break;
                   case 'after':                      
                      afterparams = afterparams + param.get('name')+'='+ param.get('defaultValue')+'&';                   
                      break;
                }//end of switch                
            }
            else
                this.params[param.get('name')] = param.get('defaultValue').replace(/\'/g, '\\"');


        }, this);//end of each




        //take care of before params:
        if(beforeparams.length>0)this.url =this.checkIfHasLast(this.url ,'/')+ beforeparams.join('/');




        //take care of after params:
        if(afterparams!=''){
          afterparams=afterparams.substring(0,afterparams.length-1);//remove last '&'
          this.url =this.checkIfHasLast(this.url ,'?') +afterparams;
        }

        //take care of usual params:

        //avoid stringify for get
        if((this.model.get('action') !== 'GET' )) this.params=JSON.stringify(this.params);
        //no params
        if(this.model.get('params').models.length==0){ this.params=null; }


        return this.url  ;
    },
    checkIfHasLast: function(url ,charMustBeLast){
        return (url[url.length-1]==charMustBeLast) ? url : url+charMustBeLast;

    },  
    displayJson: function (data) {
        var jsonstring = JSON.stringify(data, undefined, 2);
        var msg = this.syntaxHighlight(jsonstring);
        this.$el.find('pre').html(msg);
    },

    render: function () {

        this.$el.html(this.template());
        this.$el.attr("data-role", "collapsible").attr("data-theme", "c").attr("data-content-theme", "d");


        return this;
    }

});

the request send, and i get the expected json but in my developer tool i can see annoying message:

XHR finished loading: "http://localhost:8080/api/wines?_=1374143463089"

I will be very grateful if somebody can explain from where this "_=1374143463089" came

Upvotes: 1

Views: 320

Answers (1)

A. Wolff
A. Wolff

Reputation: 74410

This extra param came from option cache:false. This is to avoid cached request.

Upvotes: 1

Related Questions