• B01000111
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi,

 

I have added following Controller and Apex page and when I open the Apex page in browser using https://ap1.visual.force.com/apex/AjaxResponder?q=GetAJAX, value for the parameter "q" i.e. "GetAJAX" is displayed in browser.

 

--Start : Source Code for Controller class

public class AjaxRespController {
    String searchResult;
    /** invoked on an Ajax request */   
    public void doSearch() {
        Map<string,string> params = ApexPages.currentPage().getParameters();
        // Do SOQL query to see if there are any records !
        //List<Contact> records = getRecords(params.get('q'));
        searchResult = params.get('q');      
    }
   
    // Returns the JSON result string
    public String getResult() {
        return searchResult;
    }
}

--End : Source Code for Controller class

 

--Start : Markup for Visualforce page

<apex:page controller="AjaxRespController"  action="{!doSearch}"
contentType="text/plain; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false">
{!result}
</apex:page>

--End : Markup for Visualforce page

 

I created Home Page Component and added following following JQuery to call Apex Controller Method, but request is failing.

Also tried using relative path for the URL i.e. "/apex/AjaxResponder". But still reques is failing. Please guide me in resolving this issue.

 

-- "CallApexController" is called on click of a button which is added in page body using JQuery "Append" method in "Body" tag.

 

var j$ = jQuery.noConflict();

 

function CallApexController() {
    j$.ajax({
        type: "GET",
        url:"https://ap1.visual.force.com/apex/AjaxResponder?q=" + searchKeyword,
        contentType: "plain/text; charset=utf-8",
        data: "{}",
        dataType: "json",
        success: AjaxSucceeded,
        error: AjaxFailed
    });
}

function AjaxSucceeded(result) {
    alert('AjaxSucceeded');
}

function AjaxFailed(result) {
    alert('AjaxFailed');
}

 

 

Thanks,

Prasad
 

Hi,

 

I'm trying to do a AJAX call with this class:

global class NetsizeTest { WebService static String Test(/*String contactId*/) { return 'Test'; } }

 

 and this APEX page :

<apex:page standardController="SMS__c" extensions="NetsizeClass">
<apex:sectionHeader title="New SMS" subtitle=""/>
<apex:includeScript value="/soap/ajax/16.0/connection.js"/>
<apex:includeScript value="/soap/ajax/16.0/apex.js"/>
<script>
function getMobileNumber(input)
{
sforce.debug.trace = true;
var c_id = document.all[input.id + '_lkid'].value;
try
{
var mobilePhone = sforce.apex.execute('NetsizeTest','Test',{/*contactId:c_id*/});
alert (mobilePhone);
} catch(e)
{
alert(e.faultCode?e.faultCode:e.message?e.message:e)
}

}
</script>

<apex:form >
<apex:pageBlock title="SMS information">
<TABLE>
<TR>
<TD><B>Contact</B></TD>
<TD><apex:inputField id="smsContact" value="{!sms.Contact__c}" onselect="javascript:getMobileNumber(this)"/></TD>
</TR>
<TR>
<TD><B>Mobile phone</B></TD>
<TD><apex:inputField id="smsMobilePhone" value="{!sms.MobilePhone__c}"/></TD>
</TR>
</TABLE>
<br/>
<apex:message for="smsContact" styleClass="" /> <p />
</apex:pageBlock>

</apex:form>
</apex:page>

 but when I do the call (without the try/catch in JS), I receive a Javascript error

Message: Exception thrown and not caught
Line: 1019
Char: 13
Code: 0
URI: https://c.cs2.visual.force.com/soap/ajax/16.0/connection.js

 

When I catch the error, I get this exception:

{faultcode:'sf:INVALID_SESSION_ID', faultstring:'INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session', }

 

I get the same error with or without the parameters ContactId.

 

I get this information too, from the AJAX call debug

Request: server- /services/Soap/package/NetsizeTest

<se:Envelope xmlns:se="http://schemas.xmlsoap.org/soap/envelope/"><se:Header xmlns:sfns="http://soap.sforce.com/schemas/package/NetsizeTest"/><se:Body><Test xmlns="http://soap.sforce.com/schemas/package/NetsizeTest"/></se:Body></se:Envelope>

 

Response : status - 500

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="http://soap.sforce.com/schemas/package/NetsizeTest"><soapenv:Body><soapenv:Fault><faultcode>sf:INVALID_SESSION_ID</faultcode><faultstring>INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

 

 

I checked the session settings : timout is 4h, 'Lock sessions to the IP ...' is unchecked.

 

I don't see any mentions to a session in the doc or examples I found

Am I missing something ?

 

Thanks in advance for your help

Hervé

 

 

  • August 17, 2009
  • Like
  • 0