web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Nested ajax in javascript
Power Pages
Unanswered

Nested ajax in javascript

(0) ShareShare
ReportReport
Posted on by 53

I'm attempting to make nested ajax calls via javscript in a portal but the second ajax call never runs; 

 

 

$(document).ready(function() { 
 $("#UpdateButton").on("click", function() {
		var recodId = $("#EntityFormControl_EntityFormView_EntityID").val()
		ajaxCall1(recodId);
	});
});

function ajaxCall1(recodId)
{
 $.ajax({
	method: 'GET',
	dataType: 'text',
	url: "/xxxxxxx?recordid=" + encodeURIComponent(recodId),
 success: function(data2)
 {
	 console.log(data2);
	 alert(parseInt(data2)); //I get this alert
			
 ajaxCall2(recodId);
 }
 });
}


function ajaxCall2(recodId)
{
 $.ajax({
		method: 'GET',
		dataType: 'json',
		url: "/xxxxxx?recordid=" + encodeURIComponent(recodId),
 success: function(data)
 {
		 console.log("I found " + data.results.length + " result(s)");
		 console.log(JSON.stringify(data.results));	
		 alert(JSON.stringify(data.results));
 }
 });
}

 

 

When the first ajax call is done, I do get the alert (left a comment in the code) so I know that it is going in the success { } part of the function but the second ajax call never happens. 

 

I have tried to swap the functions i.e. call no. 2 first and then no. 1 but whatever I put as the second call, never runs. I have also run the functions by themselves and they are both successful so the issue seems to be because they are nested. I have also tried to use .done instead of success{} but still the same issue. 

 

Any one can provide any insight whether we can do nested ajax calls in a portal, please? 

 

Thanks, 

Categories:
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
sannavajjala87 Profile Picture

sannavajjala87 42 Super User 2026 Season 1

#2
Valantis Profile Picture

Valantis 33

#3
11manish Profile Picture

11manish 20

Last 30 days Overall leaderboard