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
ajax-theikosajax-theikos 

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.

Message Edited by DevAngel on 03-15-2007 01:05 PM

cheenathcheenath

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




PetroniusPetronius

I have exactly the same problem even when the code is embedded in an S-Control

P

nhebbnhebb

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>

 

PetroniusPetronius
The script you suggested produces the alert(e) from the try block - "[object error]"
It's still not able to recognize the object 'sforce', so I guess the script URL for the Ajax isn't working for me!
P
cheenathcheenath
Currently you have to be on test, na0 or na1 to use AJAX Toolkit 8.0  (winter '07).
PetroniusPetronius
DOH!!!
I'm on na3
P
cheenathcheenath
You dont have to wait long. NA3 will upgrade tomorrow.

Good luck.


Mike @ PartnersMike @ Partners
You might want to delete your log-in name and password. Just a heads up.
DevAngelDevAngel
Thanks for the heads up.  I've removed the credentials.