1

NO JQUERY. I am using peoplecode which is similar to JSP, ASP, and ZXZ. The ajax request is triggered am I am trying to pull the text 'Hello World' from this script...

Function IScript_AJAX_Test()  
   %Response.Write("<div id='hello'>Hello World</div>");  
End-Function;

My javascript function that makes the ajax call looks like this...

function AJAX_test (ajax_link) {

  if (typeof XMLHttpRequest == 'undefined') {
            XMLHttpRequest = function() {
                try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {}
                try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {}
                try { return new ActiveXObject("Msxml2.XMLHTTP"); }     catch(e) {}
                try { return new ActiveXObject("Microsoft.XMLHTTP"); }  catch(e) {}

            throw new Error('This browser does not support XMLHttpRequest or XMLHTTP.');
            };
        }
  var request = new XMLHttpRequest();
  request.onreadystatechange = function() {
    if (request.readyState == 4 && request.status == 200) {

      document.getElementById('ajax').innerHTML = request.responseText.document.getElementById('hello').innerHTML;
      //document.getElementById('ajax').innerHTML = 'Testing';
    }  
  }
  request.open('GET', ajax_link, true);
  request.send(); 

  //document.getElementById('ajax').innerHTML = ajax_link;
}

As you can see in this line..

document.getElementById('ajax').innerHTML = request.responseText.document.getElementById('hello').innerHTML;

...I am trying to grab the text by getting the innerHTML from the id. This isn't working though. When I click the button nothing happens.

I tried using the line below, but it returns an entire new page where the id would be (probably because of Peoplesoft)...

document.getElementById('ajax').innerHTML = request.responseText;

Can someone help me achieve this...

4

3 回答 3

0

让它简单:

Function IScript_AJAX_Test()  
   %Response.Write("Hello World");  
End-Function;

Javascript:

document.getElementById('ajax').innerHTML = request.responseText;
于 2012-10-25T16:53:10.710 回答
0

Ajax 可能有两种类型。一种是服务器端,另一种是客户端。您正在尝试从客户端获取数据。在这种情况下,ajax 只获取页面的整个页面结果而不是一部分。如果您编写,您将获得整个页面结果(HTML 输出)

document.getElementById('ajax').innerHTML = request.responseText;

但是你不能只获取另一个页面特定部分的 innerHtml 部分。在这种情况下,您将获得整个页面。

于 2012-10-25T17:00:52.220 回答
0

我试过你的代码,它对我有用,与

Function IScript_AJAX_Test()  
   %Response.Write("<div id='hello'>Hello World");  
End-Function;

并在 javascript

document.getElementById('ajax').innerHTML = request.responseText;

确保调用内容 servlet (psc),而不是门户 servlet (psp),例如“http: //peoplesofturl/psc/ps/EMPLOYEE/HRMS/s/WEBLIB_Z_SYS.FUNCLIB.FieldFormula.IScript_AJAX_Test ”,否则你会获取包含在 peoplesoft 门户中的响应。

您可以使用GenerateScriptContentRelURLGenerateScriptContentURL函数从 peoplecode 生成 url 。

于 2012-10-26T10:16:44.913 回答