question

Dylan Hunt avatar image
Dylan Hunt asked

AJAX Template for Playfab

I'm getting 403 errors (forbidden) when attempting to submit a js AJAX call to the API. Anyone know what I'm doing wrong?

Anyone have a working AJAX template to use a sample?

Cheers

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

What's the API method you're trying to call, specifically? Are you running this test on your local machine, or from a server? If it's local, are you running in a web server?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dylan Hunt avatar image
Dylan Hunt answered

I thought I had to jsonp but I just had to json - jsonp gave 404 - seems to be working now! On a web server, calling RegisterPlayFabUser

For anyone reading this, I got it working and want to share this as a template for others (may be syntax errs -- I tried to replace some vals to make it easier to read rather than just pasting mine):

var json =
{
"TitleId": "xxxx",
//"Username": "test_user",
"Email": $( '#emailField' ).val(),
"Password": $( '#passField' ).val()
};
$.ajax({
                
type: "POST",
url: "https://xxxx.playfabiapi.com/Client/RegisterPlayFabUser,
data: JSON.stringify(json),
contentType: 'application/json',
dataType: 'json',
timeout: 5000,
headers:
{
//'X-authentication' : Session_Token_From_Valid_Session
},
cache: false,

success: function (data)
{
if (data) {
// Success!
}
else
{
// Fail! No reg data
}
},

error: function (xhr, status, errThrown)
{
var errCode = xhr.status;
console.log("**ERR: POST returned err for: RegisterPlayFabUser:");
console.log("**" + JSON.stringify(xhr));
if (errCode == 400)
{
console.log("**PlayFab callback err is due to bad parameters: Showing fail SWAL..");
swal('Registration Failed', 'Temporary Site Maintenance', 'error');
}
}
});
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Very nice - thanks, Dylan!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.