function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesRedSalesRed 

URL Rewriter & JScript Remoting: Exception parsing json response: 'Unexpected token <'. Logged in?

Hello,

 

I am getting an error when I use JavaScript remoting and have my URLReWriter turned on on my Force.com SIte.  The error does not occur when using JavaScript Remoting with the URL ReWriter turned off.

 

The error is as follows

 

Exception Error parsing json response: 'Unexpected token <'. Logged in? 

 

I'm confused as to why this is occuring. If I have no checks for being logged in in my URL ReWriter (or visualforce page) why should this occur?

 

Has anyone ever come across something similar to this before?  I noted  the following http://salesforce.stackexchange.com/questions/4112/possible-oauth-remote-action-bug but in my case I am not using authentication on my site for the test page that I created & I'm wondering why it mentions "login".

 

Thanks in advance for any help on this.

 

Best Answer chosen by Admin (Salesforce Developers) 
SalesRedSalesRed

Hi,

 

We found the cause & solution for this.

 

In my URL Rewriter "global PageReference mapRequestUrl(PageReference rewrittenUrl){" function if I set my pagereference as "PageReference returnPageReference = Page.MyPage;"  the url rewriting will work for everything except the remote funciton.

For the Javascript remote action the pagereference should not have "/apex/MyPage" therefore thinking it needs to be logged in to function via apex pages.

 

To get around this use ""PageReference returnPageReference = new PageReference('../MyPage');" when setting the pagereference to return for a remote action.

This can be checked based on the rewrittenUrl. The reWrittenURL contains "apexremote'" if from a remote action.

 

Glad to have it sorted!

All Answers

SalesRedSalesRed

Is it possible that URLRewriters and JavaScript Remoting currently do not work together in general?

SalesRedSalesRed

Hi,

 

We found the cause & solution for this.

 

In my URL Rewriter "global PageReference mapRequestUrl(PageReference rewrittenUrl){" function if I set my pagereference as "PageReference returnPageReference = Page.MyPage;"  the url rewriting will work for everything except the remote funciton.

For the Javascript remote action the pagereference should not have "/apex/MyPage" therefore thinking it needs to be logged in to function via apex pages.

 

To get around this use ""PageReference returnPageReference = new PageReference('../MyPage');" when setting the pagereference to return for a remote action.

This can be checked based on the rewrittenUrl. The reWrittenURL contains "apexremote'" if from a remote action.

 

Glad to have it sorted!

This was selected as the best answer
Bhupendra yadavBhupendra yadav
Today I received the same error. However at the end found out that return type of the method was too complex, it was MAP of LIST. Salesforce was giving this misleading error. When I changed the return type to List or something simple, it started working.