jQuery AJAX call to script fails (SugarCRM)
Clicking an icon on a webpage triggers a jQuery AJAX call to a PHP script that synchs a local database to a SugarCRM database using SOAP.
By sending myself emails before and after the problematic statements, I can see that the SOAP connection succeeds, but the ensuing login() fails without throwing a SoapFault or a normal Exception.
From the command line, it works.
Thanks in advance for any suggestions
UPDATE: some code...
//Javascript from the webpage
url = 'http开发者_如何学C://apps.net/synch_with_CRM.php?clientGuid=141516'
// Submit via Ajax if there aren't any errors
jQuery.ajax({
url: url,
success: function(){
jQuery("#dialog-message").dialog({
buttons: {
Ok: function() {
jQuery(this).dialog('close'); /* Closes popup */
}
}
})
jQuery( "#loading_" + crm ).hide();
jQuery( "#icon_sync_" + crm ).show();
}
});
// PHP code from .../apps.net/synch_with_CRM.php
<?php
if ( $_REQUEST['clientGuid'] ) { # get the URL parameter
$client_guid = $_REQUEST['clientGuid'];
}
else if ( $argv ) { # get the command-line parameter
$client_guid = $argv[$argc - 1]; # clientGuid must be last
}
$client = new Client( $client_guid );
$client_id = $client->GetId( );
# connection information is the same for AJAX or command-line
$connection_info = getConnectionInfo( $client_id, 'SugarCRM' );
$API_soap_client = get_connection( $connection_info );
if ( !$API_soap_client ) {
exit( "SOAP client connection failed\n" );
}
# do other stuff here...
# SNIP!
function get_connection( $connection_info ) {
global $soap_session_id;
try {
$options = array( 'location' => $connection_info['url'],
'uri' => $connection_info['uri'],
'trace' => 1 );
$auth_array = array( 'user_name' => $connection_info['username'],
'password' => md5( $connection_info['password'] ) );
$API_soap_client = new soapclient( NULL, $options );
# I get the following email whether by AJAX or command-line
mail( 'programmer@apps.net', 'soapclient', print_r( $API_soap_client, true ) );
$soap_session = $API_soap_client->login( $auth_array );
# I only get this email if the script is run from the command-line
mail( 'programmer@apps.net', 'soap id', print_r( $soap_session, true ) );
$soap_session_id = $soap_session->id;
if ( $soap_session_id != -1 ) return $API_soap_client;
else return false;
}
catch( SoapFault $fault ) { # there is no SoapFault thrown
mail( 'programmer@apps.net', 'soap fault', print_r( $fault, true ) );
}
catch( Exception $e ) { # there is no Exception thrown
mail( 'programmer@apps.net', 'exception', print_r( $e, true ) );
}
} # end get_connection
?>
Anyway you could post some code to highlight the issue? Also, you may want to try doing it over REST versus SOAP since REST will be much faster.
精彩评论