top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How the following code is working?

0 votes
915 views

This is the code. I am not able to get the code flow. :

    $(document).ready(function() {
    function create_X(endpoint,data){
            response=send_recieve(endpoint,data);
            alert(response);
            alert(response.params.id);
            return response.params.id;

    function send_recieve(endpoint,data){
            var url=url_prefix + endpoint
            $.ajax({
                 url: url,
                 type: "POST",
                 dataType:"json",
                 data: data,
                 contentType:"application/json",
                 success:function(){alert("All Configurations done")},
                 error:function(){alert("ERROR")}
                 }).then(function(result){
                      alert(result.params.id);
                      return result
                 });
    $("#driver").click(function() {
        COMPUTE_X_ID=create_X("/images/compute",{"name":"compute_X_test"});

});
});

This is output I am getting:

undefined 
All Configurations done
Qwtyuetu  ->UUID

There are multiple create_X functions. At the click of a button i am trying to call all those function, for now in sequence. All these functions need to send the data to the server and get the result and send it back to create_X... functions, These function will now parse the data and return the result back.

posted Mar 18, 2015 by Prakash

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
What r u trying to do :)

2 Answers

0 votes

This is the flow -

  1. On ID driver when you click then function create_X is called
  2. create_X calls send_recieve function which makes a ajax call and ajax call is successful (from your output)
  3. You alert the response and response.params.id
answer Mar 18, 2015 by Salil Agrawal
0 votes

-> This code making ajax call using JQuery

->Create_X method generating the URL dynamically based on parameter passing from on-click.

->I would suggest you to Add (async : false) in ajax call it will execute code by order.

answer May 15, 2015 by Balamurugan Kn
Similar Questions
+3 votes

The browser i am using is google chrome. I also tested it in internet explorer and firefox too. But result is same. The post method is working fine for the same rest endpoint, but when i am trying to execute delete method on the same endpoint, it's throwing error with http status code 209 with the reason "failed to form full key for endpoint".

This is how the i am sending the delete request.

$.ajax({
             url: url,
             type: "DELETE",
             dataType:"json",
             data: JSON.stringify(data),
             crossDomain: true,
             contentType:"application/json",
             success:function(result){console.log("Success " + console.log(JSON.stringify(result)))},
             error:function(error){
                        alert("Error Deleting Service.See the console log.");
                        console.log(JSON.stringify(error));
                        },
             }).then(function(response){
                   console.log(JSON.stringify(response));
             });

The POST method:

 $.ajax({
                 url: url,
                 type: "POST",
                 dataType:"json",
                 data: JSON.stringify(data),
                 crossDomain: true,
                 contentType:"application/json; charset=utf-8",
                 success:function(){console.log("Success")},
                 error:function(error){console.log(JSON.stringify(error))},
                 }).then(function(response){
                      console.log(JSON.stringify(response));
                 });

Need help. I have already spent the day on this but not able to find the solution for this. I also tried to append the data params with the url but that too didn't worked.

0 votes

Please give the example for both.

...