You need to sign in to do that
Don't have an account?

ajax login problem
hi . i am trying to login into salesforce using new ajax toolkit.
but i could not get login.
this is the code i am tried.
<html>
<head>
<script src="https://na1.salesforce.com/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
function login()
{
try
{
sforce.connection.login("username","password");
result = sforce.connection.query("Select Name, Id from Account");
records = result.getArray("records");
for (var i=0; i<records.length; i++)
{
var record = records[i];
alert(record.Name + " -- " + record.Id);
}
}
catch(e)
{
alert(e);
}
}
</script>
</head>
29
<body onload="login()">
<div id="output"></div>
</body>
</html>
BUT i GET This Exception
"NS_ERROR_FILE_UNRECOGNIZED_PATH"
if i am using this url "<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>"
i got error like sforce is not defined.
plz any one help me out.
regards prasad.
but i could not get login.
this is the code i am tried.
<html>
<head>
<script src="https://na1.salesforce.com/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
function login()
{
try
{
sforce.connection.login("username","password");
result = sforce.connection.query("Select Name, Id from Account");
records = result.getArray("records");
for (var i=0; i<records.length; i++)
{
var record = records[i];
alert(record.Name + " -- " + record.Id);
}
}
catch(e)
{
alert(e);
}
}
</script>
</head>
29
<body onload="login()">
<div id="output"></div>
</body>
</html>
BUT i GET This Exception
"NS_ERROR_FILE_UNRECOGNIZED_PATH"
if i am using this url "<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>"
i got error like sforce is not defined.
plz any one help me out.
regards prasad.
Message Edited by DevAngel on 03-15-2007 01:05 PM
Due to the security restrictions on the browser, you can only use AJAX toolkit from an html page that is downloaded from salesforce.com. So you have to create an SControl and put this html inside the scontrol.
HTHs
I have exactly the same problem even when the code is embedded in an S-Control
P
Try this:
<html>
<head>
<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
function login()
{
try
{
var currentUrl = sforce.connection.serverUrl;
sforce.connection.login(userid,pwd);
sforce.connection.serverUrl = currentUrl;
var result = sforce.connection.query("Select Name, Id from Account");
var records = result.getArray("records");
for (var i=0; i<records.length; i++)
{
var record = records[i];
alert(record.Name + " -- " + record.Id);
}
}
catch(e)
{
alert(e);
}
}
</script>
</head>
<body onload="login()">
<div id="output"></div>
</body>
</html>
Good luck.