0
\$\begingroup\$

Am using AJAX script to have data fetched from database. For example has

  • Motorola
  • Samsung
  • Apple

as company and using AJAX to fetch models of it. Like when apple is selected then it shows apple iPhone 12, iPhone 13, iPhone 14, 14 pro max

Using this older generic script as test basis which is like years old where when a field is selected of company name, then without reloading the page models list come under it.

function createRequestObject(){var e,t=navigator.appName;return e="Microsoft Internet Explorer"==t?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest}

function getRequest(e,t,n,a){elementId=t,loading_layer_in=a,http.open("get",e),http.onreadystatechange=ManipulateRequest,http.send(null)}

function getRequestalert(e){http.open("get",e),http.onreadystatechange=function(){if(4==http.readyState){var e=http.responseText;res=e}},http.send(null)}

function ManipulateRequest(){if(""==e)var e="<FONT><B>Loading please wait.........</B></FONT>";else msg=e;if(document.getElementById(loading_layer_in)&&(document.getElementById(loading_layer_in).style.display="block"),1==http.readyState);else if(4==http.readyState){var t=http.responseText;document.getElementById(elementId)&&(document.getElementById(elementId).innerHTML=t)}}

function hideLoadingLayer(e){var t=e;document.getElementById(t)&&(document.getElementById(t).style.display="none")}

var elementId="",loadingMessage="",loading_layer_in="",http=createRequestObject();

It is working.

What is the new AJAX script in line with times which I can use as against same?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Code Review! Incorporating advice from an answer into the question violates the question-and-answer nature of this site. You could post improved code as a new question, as an answer, or as a link to an external site - as described in I improved my code based on the reviews. What next?. I have rolled back the edit, so the answers make sense again. \$\endgroup\$ Commented Dec 8, 2022 at 17:04
  • \$\begingroup\$ Ok thanks. i raised a new question \$\endgroup\$
    – Ruchika
    Commented Dec 8, 2022 at 17:46

1 Answer 1

2
\$\begingroup\$

An updated version of the code would create a new XMLHttpRequest object, which is a built-in JavaScript object that is used to make HTTP requests.

Its no longer needed to use the ActiveXObject constructor to create an XMLHttpRequest object in Internet Explorer. This method is not supported in modern versions of Internet Explorer.

It is generally not recommended to use the navigator.appName property to determine the user's web browser, because this property can be easily changed by the user or by third-party software. Instead, you can use the navigator.userAgent property, which returns a string that contains information about the user's web browser and operating system.

\$\endgroup\$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.