使用 CL_JAVA_SCRIPT 从 ABAP 执行 jQuery 文件



我想在abap中使用CL_JAVA_SCRIPT来执行一个javascript文件:jQuery.js这是我从url得到的。这是我的代码:

REPORT ZCLIENT.  
DATA: LV_CLIENT TYPE REF TO IF_HTTP_CLIENT.  
DATA:lv_URL TYPE STRING .  
lv_URL  = 'https://resources/jquery.js'.  
* Create client  
   CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL  
     EXPORTING  
       URL                = lv_URL  
     IMPORTING  
       CLIENT             = LV_CLIENT  
     EXCEPTIONS  
       ARGUMENT_NOT_FOUND = 1  
       PLUGIN_NOT_ACTIVE  = 2  
       INTERNAL_ERROR     = 3  
       OTHERS             = 4.  
   IF SY-SUBRC NE 0.  
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
   ENDIF.  
*   LV_CLIENT->REQUEST->SET_CONTENT_TYPE(  
*       EXPORTING  
*         CONTENT_TYPE = 'application/javascript; charset=UTF-8'  
*         ).  
   CALL METHOD LV_CLIENT->REQUEST->SET_FORMFIELD_ENCODING  
     EXPORTING  
       FORMFIELD_ENCODING = LV_CLIENT->REQUEST->CO_ENCODING_URL.  
* Get request:  
   CALL METHOD LV_CLIENT->SEND  
     EXCEPTIONS  
       HTTP_COMMUNICATION_FAILURE = 1  
       HTTP_INVALID_STATE         = 2  
       HTTP_PROCESSING_FAILED     = 3  
       OTHERS                     = 4.  
   IF SY-SUBRC NE 0.  
     MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO  
       WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.  
   ENDIF.  
* Prepare client-receive:  
   CALL METHOD LV_CLIENT->RECEIVE  
     EXCEPTIONS  
       HTTP_COMMUNICATION_FAILURE = 1  
       HTTP_INVALID_STATE         = 2  
       HTTP_PROCESSING_FAILED     = 3  
       OTHERS                     = 4.  
* Get HTML:  
DATA EV_DATA TYPE STRING.  
CONSTANTS co_line_size TYPE i VALUE 150.  
TYPES: t_line TYPE c LENGTH co_line_size.  
DATA: l_string TYPE string,  
      lt_lines TYPE TABLE OF t_line.  
FIELD-SYMBOLS: <l_line> TYPE t_line.  
   EV_DATA = LV_CLIENT->RESPONSE->GET_CDATA( ).  
"   compile js  
data GET_VALUE type STRING.  
data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.  
data SOURCE type STRING.  
concatenate  EV_DATA SOURCE into SOURCE SEPARATED BY cl_abap_char_utilities=>cr_lf.  
JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).  
JS_PROCESSOR->COMPILE( SCRIPT_NAME = 'TEST_GET.JS'  
  SCRIPT =  EV_DATA ).  
if JS_PROCESSOR->LAST_CONDITION_CODE <> 0.  
write: / 'Error in COMPILE',  
  JS_PROCESSOR->LAST_ERROR_MESSAGE.  
else.  
write / 'JavaScript was compiled'.  
endif.  
skip.  
JS_PROCESSOR->EXECUTE(  
exporting SCRIPT_NAME = 'TEST_GET.JS' ).  
if JS_PROCESSOR->LAST_CONDITION_CODE <> 0.  
write: / 'Error in EXECUTE',  
  JS_PROCESSOR->LAST_ERROR_MESSAGE.  
else.  
write / 'JavaScript was executed'.  
endif.  
skip.  

我的文件编译得很好,但是在执行我的代码时,我收到一些错误,例如"未定义窗口"。

应该如何解决问题

jQuery是一个JavaScript库,旨在与浏览器的文档对象模型(DOM)一起使用,它用于UI,动画,客户端逻辑等。它建立在 DOM 之上,所有功能都依赖于此,尝试在 ABAP 系统上执行 jQuery.js 文件将不起作用,因为没有浏览器,也没有 DOM 供 jQuery 交互。

您可以在 SAP 网站 ABAP 应用程序服务器页面上找到有关 ABAP 服务器及其功能和不执行操作的更多信息。

相关内容

  • 没有找到相关文章