Strategies for accessing the initial portion of an AJAX response

When using ajax to call an URL with dataType HTML, the response includes two parts such as accesstoken=1&expires=452. In this scenario, only the access token is needed. Using alert(response) displays both parts. How can the access token be extracted? The function being used is:

  $.ajax({
  type:"POST",
  url:theUrl,
  dataType:"html",
  success:function(res){
  alert(res);
  }
  });

Answer №1

If you want to separate a string into different parts, you can utilize the split function as demonstrated below.

let example = "username=johndoe&id=123";
let sections = example.split("&");
console.log(sections[1]);

Answer №2

To achieve this task, you can utilize the split function like so:

Here is an example:

 $.ajax({
     type:"POST",
     url:theUrl,
     dataType:"html",
     success:function(response){
         alert(response);
         var parsedResponse=response.split('&');
         var accessToken=parsedResponse[0].split('=');
         var accessTokenValue=accessToken[1];
      }
 });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Rails to render partials with Ajax and buttons

I have a webpage that showcases a list of microposts along with different tabs like Most Recent, Most Discussed, and Most Viewed. I am looking for a way to dynamically render the various list orders of microposts without having to refresh the entire page u ...

Here is a way to retrieve the name of a ref object stored in an array using Vue.js 3 and Typescript

I have a Form, with various fields that I want to get the value of using v-model and assign them to ref objects. In order to populate my FormData object with this data, I require both the name and the value of the ref objects. Unfortunately, I am struggli ...

Pause before sending each request

How can we optimize the Async Validator so that it only sends a request to JSON once, instead of every time a letter is typed in the Email form? isEmailExist(): AsyncValidatorFn { return (control: AbstractControl): Observable<any> => { ...

Issues with displaying public images in Next.js production build are being reported

My Next.js app is deployed on Heroku. Images show up when I develop locally, but once pushed to Heroku and checked on the live site, the images return a 404 error. The images (.png) are stored in a public folder within my project, and I reference them in t ...

What is the best way to implement a unique function in an angularjs directive?

Is it possible to execute a custom function when clicking on the checkbox of a table row shown below? I am using the Angular Smart Table directive and need to be able to store the rowid or another property of the rows when the checkbox is clicked. app.dir ...

Send arguments to Datatable

I am looking for a way to transfer parameters from an ajax datatable to filter information. Here is what I have: My goal is to pass the select "nombremedico" and two inputs - initial_date and final_date - to fetch_pasar.php in order to filter information ...

Adding a custom class to the body element for specific routes in Next.js can be achieved by utilizing the features of

I am looking to apply my custom class to certain pages, with the exception of specific routes. For example, all pages should have the class fixed-header, except for the following routes: /cart/step-1 /login This class should be added or removed from the ...

A simple guide on how to surround every incorrect input index in mapped inputs with red borders

I am incorporating a modal that corresponds each element of the object newCompanies to a specific row: {newCompanies.map((company, index) => { return ( <div> <div className="side- ...

AJAX form submission with real-time validation error detection

I am currently working on a project using Symfony 3 with FOSUserBundle and integrating Bootstrap modal. The current setup : I have successfully loaded the FOSUserBundle login form within a modal window. Form submission is done via AJAX for a seamless us ...

Is there a way to clear the list after each input is made?

Looking for help with the Ping Pong Test. Whenever I click Start and enter a number, it just keeps adding to the list. How can I make it reset the list after each input? $(document).ready(function() { $("#Start").click(function() { ...

Is there a way to verify the presence of a particular value in a list?

I need to validate the content of all li tags within a ul list. If any list item contains the text "None," then I want to append specific text to a div. If no li tag includes "None," then different text should be added to the div. Upon checking my code, I ...

Angular 2 template is nowhere to be found

As a newcomer to Angular 2, I am currently developing an app where I have successfully completed the Root component containing a navigation bar and footer. However, as I delve into working on the homepage module, I encountered an error. [Error] Unhandle ...

Debouncing in AngularJS with $watch

In my code, I have an HTML search field represented by the following: <input ng-model-options="{ debounce: 500 }" type="text" ng-model="name"> Along with the JavaScript snippet: $scope.$watch('name', function(newVal, oldVal) { ...

Phonegap app: The function in the AngularJS controller is only executed when called twice

I am currently developing a phonegap app using angularJS, and I have encountered an issue with a function in one of my controllers. Here is how my controller looks like: function NavCtrl($scope,navSvc) { $scope.slidePage = function (path,type) { ...

Utilizing a custom filter for object manipulation within Vuetify's v-autocomplete

When using vuetify v-autocomplete with an object where the object consists of Key-Value pairs, the search functionality is based on the item-text. In my example, I am displaying the object as {1200-Chloride Systems}. Is it possible to make the search funct ...

The Challenge of Referencing Javascript Files (including jQuery)

Previously, I had the following code snippet: <head> <script src="/Scripts/jquery-1.3.2.min.js" type="text/javascript"></script> <script type="text/javascript"> var optPrompt = "- Select One -"; var subCats ...

What is the best way to extract an object by its specific id using json-server?

I am attempting to retrieve an object by its id using json-server. If I only return a single variable (one JSON) in the module.exports of the database file, everything works fine. However, if I try to return an object with multiple variables, I encounter a ...

Having trouble with the Angular router link suddenly "failing"?

app.routes.ts: import { environment } from './environment'; import { RouterModule } from "@angular/router"; import { ContactUsComponent } from './static/components/contact-us.component'; import { HomeComponent } ...

Generate a customizable URL for my search bar

I have developed a single HTML page with full AJAX functionality, displaying all content including form submits, main page, form results, and more through various DOM manipulations. The issue I am currently encountering is related to a search box where use ...

I'm facing issues with Angular commands not functioning properly even after installing the Angular CLI and configuring the

Every time I attempt to create a new project using Angular CLI by typing: ng n app I encounter the following error message: C:\Users\Venkateshwarn M\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng: ...