简体   繁体   中英

Meteor Call - Exception in template helper

I'm trying to make a method call in client, but I get

Exception in template helper: Error: Syntax error, unrecognized expression: https://www.example.com

I'm using a Meteor method to parse a URL in XML to get some data, so my variable is a string URL

Method

 rank: function(postAttributes) {
    check(postAttributes, {
      url: String
    });
    var alexa = require('alexarank');
    var alexaSync = Meteor.wrapAsync(alexa);
    var result = alexaSync({url: postAttributes.url});
    return result.rank;
  }

Client Call

function() {
    var a = document.createElement('a');
    a.href = this.url;
     var post = {
      url: $(a.href)
    };
    Meteor.call('rank', post, function(error, result) {
      // display the error to the user and abort
      if (error)
        return throwError(error.reason);
      // show this result but route anyway
      return result;
    });
  }

Any idea?

Perhaps $(a.href) is not returning a String and the template executes the url as if it was javascript code.

Try using:

url: '' + $(a.href)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM