【问题标题】:jQuery AJAX call to script fails (SugarCRM)jQuery AJAX 调用脚本失败 (SugarCRM)
【发布时间】:2011-08-04 20:54:10
【问题描述】:

单击网页上的图标会触发对 PHP 脚本的 jQuery AJAX 调用,该脚本使用 SOAP 将本地数据库与 SugarCRM 数据库同步。

通过在有问题的语句之前和之后给自己发送电子邮件,我可以看到 SOAP 连接成功,但随后的 login() 失败,没有抛出 SoapFault 或正常的异常。

从命令行,它可以工作。

提前感谢您的任何建议

更新:一些代码...

//来自网页的Javascript

    url = 'http://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();
       }
     });

// 来自 .../apps.net/synch_with_CRM.php 的 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
?>

【问题讨论】:

  • 这不是超时问题 - 只要尝试调用 SOAP,脚本就会结束。

标签: php web-applications jquery soap sugarcrm


【解决方案1】:

无论如何你可以发布一些代码来突出这个问题?此外,您可能想尝试通过 REST 而非 SOAP 来实现,因为 REST 会快得多。

【讨论】:

  • 此脚本适用于 SugarCRM 5.2、5.5 和 6.1(我们的客户都使用)——REST 仅适用于 5.5+
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 2019-03-31
  • 1970-01-01
相关资源
最近更新 更多