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

Notifications

Announcements

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 74 Super User 2025 Season 2

#2
Jerry-IN Profile Picture

Jerry-IN 55

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard