4

This is driving me nuts. I have the most simple JSRemoting setup and for whatever reason I can not get this VF page to render on my Contact Layout. It's giving me a cross domain error and the only way that I can fix it seems to be to remove the @RemoteAction annotation from the controller/extension. I searched the net and saw other people were able to remote from a standard layout and I thought JSRemoting was supported in this use case?

Anyway, I'm getting this error from the console :

Uncaught SecurityError: Blocked a frame with origin "https://c.cs20.visual.force.com" from accessing a frame with origin "https://cs20.salesforce.com". Protocols, domains, and ports must match.

Even if I am not referencing the remote action I get it but if I remove the @RemoteAction annotation, the error goes away.

Any help would be greatly appreciated. Here is the super simple code I'm trying to use :

<apex:page applyHtmlTag="false" standardStylesheets="false" controller="jrTesting" 

showHeader="false" >
 <script type="text/javascript" src="{!URLFOR($Resource.Bootstrap3, 'bootstrap_3.1.1/js/jquery-1.11.0.min.js')}"/><apex:messages />
<html>
<head>
</head>
<body>
<p id="ts" >This is my paragraph...</p>



<script type="text/javascript">

var $j = jQuery.noConflict();
$j(document).ready(function() {

console.log($j("#ts").text());

$j("#ts").text("New Text here!");
callRA();
callRA2();
});



function callRA() {
 Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.jrTesting.getTheString}',
            function(r, e){           
             $j("#ts").text(r);  
            });

}

function callRA2() {
jrTesting.getTheString(function(r, e){           
             $j("#ts").text(r + ' from number 2!');  
            });

}


</script>

</body>
</html>
</apex:page>

controller :

public with sharing class jrTesting {

    public jrTesting() {

    }




    @RemoteAction
    public static string getTheString() {
        return 'Here is my return string';
    }

}

**UPDATE To access it, the class and methods need to be global!**

4

Thanks for your response, @Regal. Well, after reading further, I am a dummy! Apparently you have to make your class and method Global! Anyway, for anyone else out there banging their head on the table about this, you can find the answer in the JSRemoting documentation here

@RemoteAction Scope Visualforce Page    Non-Global Component    Global Component    

iframe
Global Remote Method    Allowed Allowed Allowed Allowed
Public Remote Method    Allowed Allowed Error   Error
2

As the error says: The remoting url of the visualforce page is different from the url of Standard layout page So, browser security do not allow this cross domain request.

Visualforce remoting is a stateless ajax call which cannot be happened to different url,port or protocol from the url in which it initiated.

You can see remote url is: https://c.cs20.visual.force.com/ and page url is https://cs20.salesforce.com/ They have different domains. To make this call successful, domain,protocol and port must be same.

I would recommend to use <apex:actionfunction> if you can use Apex controller on visualforce page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.