SAP-CRM-WEBSHOP: How to call custom Function Modules #63

[It’s a little tricky – I really should re-write this.]
Pre-requisite: knowledge in J2EE, Struts, SAP CRM Webshop, HTML
What this article will provide? Just a very upper level description on how to call your own function modules, or SAP built-in function modules that are not called by the standard application/webshop.

What are function modules?

SAP provides many different function modules to execute different operations [back end operations]. You can also consider them as stored procedures in traditional DBMSs like Oracle, SQL Server, MySQL, and PostGreSQL. Usually, you call the backend stored procedures from the front end [say Java programs], supply some input parameters to the stored procedures, and collect outputs for further processing [or just display]. Same is true for SAP. In CRM Webshop, one strategy is that you can have backend objects in your applications and these backend objects can have functions that execute the function modules.

An example:

From a JSP page when the form is submitted, you want to execute a custom function module [written by you]. The JSp page will collect shopId from the user and display the shop description. Your function module will retrieve the shop description and pass it to the JSP/Java program for display.

Implementation Requirements: You will need to implement a business object, a backend object, a custom business object manager. Also, you will need to register these objects in the Internet Sales Framework (SAP-ISA).

Steps: In the JSP page create a text box to collect the shop id, and refer the form action to the custom action (z_test.do) as action=”z_test.do”. Map the action z_test.do to the action class Z_CustomAction in your configuration file named config.xml as follows:

When users will provide the shop id and click on the submit button the doPerform() method of the class Z_CustomAction will be executed. In the Z_CustomAction class, in the doPerform() method, you have to get a reference to the custom business object manager(bom) as

Z_CustomBusinessObjectManager myBOM = (Z_CustomBusinessObjectManager)userSessionData. getBOM(Z_CustomBusinessObjectManager.CUSTOM_BOM);
[you need to write this BOM class Z_CustomBusinessObjectManager also. userSessionData is the sap wrapped session object]

then use the custom BOM object (myBOM) to retrive the CustomBasket [Basket = shopping/order basket] as

myBOM.getCustomBasket()

where the CustomeBasket is of Z_CustomFunc type [i.e. myBOM.getCustomBasket() returns Z_CustomFunc type object, You need to write Z_CustomFunc class as well].

Then call the getShopDescription(id) method of the Z_CustomFunc class as

String shopDescr = myBOM.getCustomBasket().getShopDescription(shopId);

As mentioned that the custom basket is of type Z_CustomFunc class with methods such as getShopDescription(id) [getShopDescription of Z_CustomFunc eventually will go to the lowest level to call the function module]. In Z_CustomFunc class in getShopDescription(id), you will call the getShopDescription(id) method of the backend object Z_CustomFuncBackend [you have to write the interface] as

return getCustomBasketBackend().getShopDescription(shopId);

[In getShopDescription(id) method of Z_CustomFunc]
here through getCustomBasketBackend()[method of Z_CustomFunc] you get a reference to the backend object Z_CustomFuncBackend, then call the method getShopDescription of Z_CustomFuncBackend. In getCustomBasketBackend() method, you practically create the backend object Z_Custom of Z_CustomFuncBackend type. Then you map Z_Custom to Z_CustomFuncCRM class/object in the backendobject-config.xml file. Then, in Z_CustomFuncCRM, you need to define the method getShopDescription(id) where the actual/lowest level call to the function module will be done as follows:

JCO.Function func = getDefaultJCoConnection().getJCoFunction(“CRM_ISA_SHOP_GETLIST”);
func.getImportParameterList().setValue(“B2B”, “SCENARIO”);
getDefaultJCoConnection().execute(func);

CRM_ISA_SHOP_GETLIST is the name of the underlying custom function module. Also, in this method, you can write code to collect information from the function module for further processing or display.Configurations
backendobject-config.xml for Z_Custom backend object

Also, list your BOM in the config file bom-config.xml as

——————-Additional Information———————–

BOM class that have functions to get/point to the custom basket, bom gets reference to the custom basket through backend object manager as

mCustomBasket = new Z_CustomFunc();
assignBackendObjectManager(mCustomBasket);
mCustomBasket is the custom basket to be returned

—Z_CustomFunc has methods like

getShopDescription: that calls
getCustomBasketBackend().getShopDescription(shopId);

where getCustomBasketBackend() Returns a reference to the backend object Z_CustomFuncBackend that you also need to write. CustomFuncBackend is just an interface with method declaration such as getShopDescription(id)

Also, you need to write a class that handles the function module call and data retrieval say Z_CustomFuncCRM withgetShopDescription(id) function that may include:

JCO.Function func = getDefaultJCoConnection().getJCoFunction(“CRM_ISA_SHOP_GETLIST”);
func.getImportParameterList().setValue(“B2B”, “SCENARIO”);
getDefaultJCoConnection().execute(func);

—–Reference: SAP CRM ECommerce – Development and Extension Guide

From: http://sitestree.com/?p=5026
Categories:63
Tags:
Post Data:2013-03-24 12:36:42

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

What to learn for SAP Ecommerce #63

Why SAP? SAP is the most dominating company in the Business Application World. Yes, SAP is for big enterprises [SAP recently released software for small and mid-size companies]. The earnings of the SAP professionals are also very high. Microsoft is dominant mostly in the personal computer software/os domains. However, SAP, IBM, Oracle, and Sun are the most dominant companies in the business application world.

Though computer science is not about business/application software but about system software, still most computer students are employed in the business/application software area. Yes, IT and CIS are about business/application software.

SAP has different modules like CRM, SRM, SCM, and many others. Search this web-site for more articles on the overview of SAP. It’s better to find an area of interest in SAP and be expert in that. Afterwards, you can try to learn other modules as required. In mySAP ERP, ecommerce/webshop is a recent extension. It implements enterprise ecommerce systems on top of SAP.

SAP Ecommerce Framework has three layers: Interaction and presentation layer, Business object layer (BO Layer), and Business Logic Service Layer (BLS Layer)

Presentation Layer: SAP favors JSP in terms of presentation layer. SAP extensions to JSP include: Custom ISA tags, MimeURL, WebappsURL, translate, iterate, contentType, message, imageAttribute, moduleName.

In presentation layer, you also need to be familiar with dynamic field control concepts such as UI element objects, UI element group objects, and configuration of fields via XCM admin, xcmadmin-config.xml file, and conf-data.xml file.

Interaction Layer:You should be familiar with the UI components, Interaction Components such as Actions, Threads in Actions, ActionForms, Interaction configuration like ActionServlet, ActionFormBean, ActionMapping, ActionForward, ISA extensions of struts such as com.sap.isa.core.InitAction, com.sap.isa.core.BaseAction, com.sap.isa.isacore.action.ECOmBaseAction, com.sap.isa.core.UserSessionData, and also multiple languages integration using resource keys.

Interaction layer includes some other additional concepts such as Input Validation, HTTP Header Information, Cross Site Scripting, User Authentication. You are also required to master these concepts.

Business Object layer includes different business objects such as Customer, Order, and Basket.

Business Logic Service Layer (BLS Layer): You need to master the Backend Objects, Backend Object Manager, Connection Management such as JCo based connections, and Working with JCo functions.

BLS also includes a Message Framework that includes messaging classes such as Message, MessageList, and MessageListHolder, Message Tags, and default error pages such as appbase/backenderror.jsp.

BLS also includes a Generic Search Framework, also Logging and Tracing capabilities.

Reference: SAP Developer Extension Guide – SAP Ecommerce 5.0

From: http://sitestree.com/?p=5019
Categories:63
Tags:
Post Data:2009-06-13 11:11:54

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SAP Web Shop Resources #63

From: http://sitestree.com/?p=5005
Categories:63
Tags:
Post Data:2009-04-25 13:54:21

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

How to call SAP Function Module/RFC from Java #63

From: http://sitestree.com/?p=4988
Categories:63
Tags:
Post Data:2010-10-22 20:50:44

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SAP Overview #63

  • Introduction to ERP and SAP
    • Enterprise Resource Planning (ERP) – helps to manage and operate business processes effectively and in an integrated/co-ordinated fashion. The integration nature helps businesses to understand their business/business processes more effectively and make decision intelligently
    • ERP makes use of IT to integrate all business processes into a single co-ordinated system
    • In ERP only one integrated database is used that is shared among all the business departments. Operational data from all business departments such as production, sales, finance, hr, customer service, SCM come into the same database. Hence, data are more consistent and complete. The database may not be in one single physical location, but can be distributed and integrated database
    • As you get all the information in the same place, generating cross-department reports, applying BI to these data become easier and more meaningful. Getting overall picture of the company becomes much easier (than multiple DBMS). It helps the management take important decisions and plan the company future more effectively
    • If all the departments were using separate databases for their operations, it would be harder to generate cross-functional reports, and get overall picture of the company. Merging different databases also would become a big headache.
    • Additionally, Many jobs require inter-department communications. ERP makes such communication easier/faster, more manageable
    • If all the departments were using separate databases/systems, interdependent activities would require to insert data (relevant to the dept) in all the databases separately – more work, require more time, more error prone. If a change is needed, the change needs to be done in multiple places – again the three mores. The departments would require to submit individual reports to the management – more difficult for the management to understand the areas of the interdependent activities
    • To address such issues ERP came into play
    • Evolution: MRP, MRP II, ERP
    • MRP: Materials Requirements Planning: 1960: To control inventory management. Overstock or lower-stock inventory control
    • MRP II: Manufacturing Resource Planning: 1970s: for manufacturing companies to automate production, sales, marketing, HR, Finance: focused manufacturing businesses only.
    • ERP: 1990s: For standard business organizations addressing any type of business.
  • SAP
    • SAP: Systems, Applications Products: Was established in 1972
    • Versions of SAP: R/2 (late 1970s), R/3 (early 1990), mySAP ERP (late 1990), standard business products, industry specific products, for small and mid-size enterprise solutions
    • R/2 for mainframe platform with character based clients, R/3 improved R/2 to support diversified and changing technologies, mySAP ERP further improved R/3 to support ebusiness
    • mySAP ERP: has many modules such as Finance, HR for specific departments, also integrates related modules
    • mySAP ERP features: process auditing, centralized system management, centralized operation management, integrated and modular model, integration with non-SAP systems with netweaver platform, e-business support
    • mySAP ERP solutions: CRM (Customer Relation Management), ERP (Enterprise Resource Planning), SCM (Supply Chain Mgmt), SRM (Supplier Relationship Management), PLM (Product Lifecycle Management)
    • SAP solutions for small and mid size enterprises (SMEs): SAP Business One, mySAP All-in-One
    • Industry specific solutions: Aerospace and Defense, Oil and Gas, Banking, Media
  • mySAP:
    • R/3 introduced GUI for SAP. Latest version for SAP R/3 is the Enterprise Central Component (ECC) = core component of mySAP ERP.
    • mySAP: Three tier architecture: presentation, application, data. Presentation: GUI, application: processes, Data: storage and manipulation of data
    • SAP tasks: functional, technical
    • Functional: end user carry out an operation
    • Technical: Administrators and programmers – update SAP system
    • each task is considered as a transaction, each transaction is associated with a transaction code
    • ME21 – functional – purchase order, SE38 – technical – work with ABAP (Programming Language for SAP) editor
    • SAP Data: Organizational Structure, Master Data : needs to be created before a SAP systems come into operation.
    • Organizational Structure – structure of the organization – people – departments. Master: example: a list of suppliers – change more frequently than organizational structure
    • Reporting in SAP R/3: creating report programs (create with ABAP), generating report lists – programmed report programs

From: http://sitestree.com/?p=4980
Categories:63
Tags:
Post Data:2010-05-03 12:18:18

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Developing J2ee Applications for SAP #63

From: http://sitestree.com/?p=4976
Categories:63
Tags:
Post Data:2007-07-05 23:54:32

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SAP: Career Prospects #63

From: http://sitestree.com/?p=4962
Categories:63
Tags:
Post Data:2011-03-30 13:12:24

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SAP: Resources #63

From: http://sitestree.com/?p=4959
Categories:63
Tags:
Post Data:2007-12-15 01:40:15

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

SAP JCo Connector #63

From: http://sitestree.com/?p=4957
Categories:63
Tags:
Post Data:2010-05-22 09:51:45

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>

Ajax: An Overview #65

  • Ajax: dynamically changes a portion of the current web-page without refreshing the total web-page. Resembles the way IFrame works. So far I know, google uses IFrame to display/refresh maps in web-pages
  • XMLHttpRequest is the object that serves the purpose of Ajax
  • The way it works: create an instance of the XMLHttpRequest object, send request to the back-end web-page that will do some processing and perhaps return some data, receive the response data, dynamically change the content of the target area, you may need to get a reference to the target area using DOM, after sending request – you have to wait for the response to come back
  • create an instance of the XMLHttpRequest object: It varies for the different browsers. IE provides ActiveX Control for the purpose. A sample code can be as follows:
  •   function getAjaxObject(){    var ajaxObject = false;    if (window.XMLHttpRequest){         ajaxObject = new XMLHttpRequest();    }else if (window.ActiveXObject) {      try{        ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");      }catch(e){         try{          ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");         }catch(e){           ajaxObject = false;         }      }    }    return ajaxObject;   }
  • XMLHttpRequest has three core components. onreadystatechange – event to notify response has come or identify server activity, open – method , send method
  • use of onreadystatechange
    if (ajaxObject){//takeAction - reference to a function   ajaxObject.onreadystatechange = takeAction; }
  • Open method specifies the server side script to handle the request, data to send to the server, method of sending (GET, POST) : Required: type of request (first argument), location of the file in the server (2nd argument)
  • Open method: third argument: true = processing will be done asynchronously, false = synchronous processing – browser will stop processing until response comes [true is usually better]
  • send : send method initiates the request : also passes data to the server
  • For GET method the argument can be set to null, for POSt method the argument can be a query string such as “id=500&name=keith&age=18”
  • use setRequestHeader() – to provide metadata
  • Sample code:
     var ajaxObject = getAjaxObject(); if (ajaxObject ){    ajaxObject.onreadystatechange = takeAction;     ajaxObject.open("POST","file.jsp", true);    ajaxObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    ajaxObject.send("id=500&name=keith&age=18"); }
  • How to receive and process the response:
  • The readyState property indicates the current status of the request. 0 – Uninitialized, 1 – Loading, 2 – Loaded, 3 – interactive, 4 – complete
  • each time the value of readyState changes onreadystatechange – event is triggered. At value 4, we can collect the response and change the web-page dynamically
  • Sample:
     function takeAction(ajaxObject){  if (ajaxObject.readyState == 4) {     //do something with the response  } }
  • status is another property to consider – it indicates the status of sending request like 404 – not found, 200 = success, 304 = not modified
  • The prev function
     function takeAction(ajaxObject){  if (ajaxObject.readyState == 4) {     if (ajaxObject.status == 200 || ajaxObject.status == 304){ //response was sent succesfully           //do something with the response     }  } }
  • responseText is the response from the server
  •  function takeAction(ajaxObject){  if (ajaxObject.readyState == 4) {     if (ajaxObject.status == 200 || ajaxObject.status == 304){ //response was sent succesfully           //do something with the response          alert(ajaxObject.responseText);     }  } }
  • responseXML can be used when the response was sent as xml and the response header is “text/xml”
  • All together
      function getAjaxObject(){    var ajaxObject = false;    if (window.XMLHttpRequest){         ajaxObject = new XMLHttpRequest();    }else if (window.ActiveXObject) {      try{        ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");      }catch(e){         try{          ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");         }catch(e){           ajaxObject = false;         }      }    }    return ajaxObject;   }  function entryPoint(){    var ajaxObject = getAjaxObject();     if (ajaxObject ){    ajaxObject.onreadystatechange = function(){      takeAction(ajaxObject);     };    ajaxObject.open("POST","file.jsp", true);    ajaxObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    ajaxObject.send("id=500&name=keith&age=18"); } } function takeAction(ajaxObject){  if (ajaxObject.readyState == 4) {     if (ajaxObject.status == 200 || ajaxObject.status == 304){ //response was sent succesfully           //do something with the response          alert(ajaxObject.responseText);          var testDiv = document.getElementById("test");          testDiv.innerText = ajaxObject.responseText;      }  } }
  • Processing Response Data
  • The usual practice: response data can be in one of three formats: XML, JSON, HTML. And may be plain text.
  • XML is the most common. example receive: var data = ajaxObject.responseXML; Here we can use the DOM functions to parse the XML data
  • Example:
    var data = ajaxObject.responseXML;data.getElementsByTagName("name")data.getElementsByTagName("name")[0]data.getElementsByTagName("name")[0].firstChilddata.getElementsByTagName("name")[0].firstChild.nodeValueSimilarly, you can use other DOM functions
  • To change the contents of the web-page dynamically, you can use the DOM methods like — create, set, innerText, innerHtml (use carefully) methods. Check the JavaScript DOM article [846] in this web-site. adding and removing childs/elements may be required in some situations – DOM also supports that
  • You can also send data as JSON from the server side like: JSON format:
    {“person”:{ “name”:”Keith Tang”, “school”:”uofm” }}
  • Receiving and extracting information from JSON: [content type will be text]
     var data = eval('('+ ajaxObject.responseText +')'); var name = data.person.name; var school = data.person.school; 
  • Response data as HTML
  • The response can come as HTML. This may be useful, if only one area of the web-page is affected and we want to put the HTML response in that area. Otherwise it may not be great. Also, we need to use innerHTML method that was introduced by IE and later adopted by others. Still, it’s not a standard (W3C)
  • Example: The content type of response data should be text/html
           if (ajaxObject.status == 200 || ajaxObject.status == 304){ //response was sent succesfully           //do something with the response          alert(ajaxObject.responseText);          var testDiv = document.getElementById("test");          testDiv.innerHTML = ajaxObject.responseText;      }

From: http://sitestree.com/?p=4969
Categories:65
Tags:
Post Data:2009-03-30 16:04:56

    Shop Online: <a href='https://www.ShopForSoul.com/' target='new' rel="noopener">https://www.ShopForSoul.com/</a>
    (Big Data, Cloud, Security, Machine Learning): Courses: <a href='http://Training.SitesTree.com' target='new' rel="noopener"> http://Training.SitesTree.com</a> 
    In Bengali: <a href='http://Bangla.SaLearningSchool.com' target='new' rel="noopener">http://Bangla.SaLearningSchool.com</a>
    <a href='http://SitesTree.com' target='new' rel="noopener">http://SitesTree.com</a>
    8112223 Canada Inc./JustEtc: <a href='http://JustEtc.net' target='new' rel="noopener">http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning) </a>
    Shop Online: <a href='https://www.ShopForSoul.com'> https://www.ShopForSoul.com/</a>
    Medium: <a href='https://medium.com/@SayedAhmedCanada' target='new' rel="noopener"> https://medium.com/@SayedAhmedCanada </a>