I was tried to retrieve the value from ajax (success function) to PHP function on same page. But I can't retrieve the value can anyone please help for this.
function example_init(){
drupal_add_js('$(document).ready(function () {
var url2 = (window.location.search).replace("?", "");
//alert(url2);
$.ajax({
headers: {"Content-Type": "application/x-www-form-urlencoded" },
type: "POST",
url: "https://pub.orcid.org/oauth/token",
data : "client_id=APP-056GSP3J5RDSCM&client_secret=f5fcc4c58-88c3-92d02be078dd&grant_type=authorization_code&redirect_uri=http://localhost/drupal/examples/example/&"+url2,
success: function (response) {
var orcid_id = response.orcid;
var name = response.name;
// this value should pass to function example($form, &$form_state){}
alert(name);
//console.log(response);
},
error: function (error) {
console.log(error);
},
});
});', 'inline');
}
function example($form, &$form_state) {
// Ajax's success function value should retrieve here
return user_external_login_register('test@gmail.com', 'user');
}
Comments
This makes no sense - an ajax
This makes no sense - an ajax response comes from the server (PHP), and you are saying you want to pass the response to a function on the server.
You can do this all on the server, without using the ajax.
Contact me to contract me for D7 -> D10/11 migrations.