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
SuriSuri 

Logging into Salesforce from outside Salesforce using connection.js

Hi

 

I have a page where I have used the "connection.js" to Login into a Salesforce instance.

 

But I am receiving errors when I try to do this.

 

When I host it from a Local Server or on a Salesforce Sites page, I get the error:

 

[Exception... "Access to restricted URI denied"  code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"  location: "https://na6.salesforce.com/soap/ajax/16.0/connection.js Line: 594"]

 

Can anyone tell me why this error occurs? And what should be done for successful Login?

 

I have provided my code below. Its a simple JS code that calls the Login method.

 

 

================ CODE ==============================

 

<HTML>
<HEAD>

<script src="https://na6.salesforce.com/soap/ajax/16.0/connection.js" ></script>

<script type="text/javascript" >

function logincall()
{

    try{
   
    sforce.connection.serverUrl = 'http://www.salesforce.com';
   
    var usrname = document.getElementById('userid').value;
    var passwrd = document.getElementById('passid').value;

    if(usrname == null || usrname == '' || passwrd == null || passwrd == '')
    {
        alert('Please enter Username AND Password');
        return;
    }
   
    var result = sforce.connection.login(usrname, passwrd);

    alert("Logged in with session id " + result.sessionId);
    }
    catch(error)
    {
        alert(error);
       
    }

}

</script>

</HEAD>

<BODY>


To test logging into a Salesforce Instance using the connection.js "login" call


<table>
        <tr>
            <td>Username</td>
            <td><input type="text" id="userid" value="" /></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type="password" id="passid" value="" /></td>
        </tr>

</table>


    <input type="button" value="Login" onclick="logincall();" />

</BODY>

</HTML>

 

================ CODE ==============================

SuriSuri
AWESOME!! now what's that supposed to mean?
sidbsidb

Where you able to resolve this? I am also trying to access AJAX toolkit through HTML. Any help would be great.

SuperfellSuperfell

If you're trying to use the ajax toolkit from a page that's not from salesforce.com, then its not going to work, because the browser will enforce the cross domain policy, stoping the connection. Typically in these scenarios you need to look at things like jsonp (not currently supported by salesforce) or have a server proxy (i.e. the server handling your html will proxy ajax requests to salesforce, so that the browser only talks to one domain.), obviously, you need to be careful about security issues if you go this route.

Ranu JainRanu Jain

Hii.,

i am facing the same problem....how u solved this?  please  suggest ..i really need the solution.

 

 

thanks

 

riffindusriffindus
Hello,

I am trying the same and i am getting the same error message. Any help will be appreciated.

Aariff