After the Ajax post

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gundogduyakici
    Senior Member
    • Mar 2018
    • 165

    After the Ajax post

    I am redirecting to the post-Ajax post creation page. After redirecting, I want to auto-fill the name field on the build page with the data I get from ajax. Is this possible ?

    Code example;
    Code:
    $.ajax({
        url: 'Meeting/action/Test',
        type: 'POST',
        data: JSON.stringify({
            phone: phone
        }),
        success: function (data) {                        
            if(data.status == 409){                            
                console.log("duplicate");
            }else{
                // I want auto-fill name field. ?
                window.location = '#Meeting/create';                            
                self.close();
            }
        }
    });
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hi,
    EspoCRM – Open Source CRM Application. Contribute to espocrm/espocrm development by creating an account on GitHub.

    Comment

    • gundogduyakici
      Senior Member
      • Mar 2018
      • 165

      #3
      Thanks for quick reply. tanya

      But I use click event

      Code:
      events: {
          'click #gonder': function (e) {
              var self = this;
      
              var $phone = this.$el.find('input[name="phone"]');                
              var phone = $phone.val();
      
              $.ajax({
                  url: 'Meeting/action/Test',
                  type: 'POST',
                  data: JSON.stringify({
                      phone: phone
                  }),
                  success: function (data) {                        
                      if(data.status == 409){                            
                          self.$el.find('#duplicate').removeClass('hidden');
                      }else{                            
                          window.location = '#Meeting/create';                            
                          self.close();
                      }
                  }
              });
          }
      },
      How do I do it here? Could you give a simple example?

      Comment

      • tanya
        Senior Member
        • Jun 2014
        • 4308

        #4
        ? I show you a method, which navigate to other url with set attributes. Build your attributes and options go to your page with router
        window.location - is not the best solution for single page application

        Comment

        • gundogduyakici
          Senior Member
          • Mar 2018
          • 165

          #5
          I understand. I will do this. Thank you. tanya

          Comment

          • gundogduyakici
            Senior Member
            • Mar 2018
            • 165

            #6
            I did what you said, but I can not find the functions. tanya

            Uncaught TypeError: this.getRouter is not a function , model, fetch vs..
            They can not find any of them.

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              self.getRouter() ?

              Comment

              • gundogduyakici
                Senior Member
                • Mar 2018
                • 165

                #8
                Yes, it works that way. But the others are not working. tanya

                Uncaught TypeError: Cannot read property 'fetch' of undefined.
                Uncaught TypeError: Cannot read property 'model' of undefined

                Comment

                • tanya
                  Senior Member
                  • Jun 2014
                  • 4308

                  #9
                  is a view valid? commas and '(', '{', '}', ')'

                  Comment

                  • gundogduyakici
                    Senior Member
                    • Mar 2018
                    • 165

                    #10
                    Originally posted by tanya
                    is a view valid? commas and '(', '{', '}', ')'
                    Here is all I do.

                    Code:
                    events: {
                        'click #gonder': function (e) {
                            var self = this;
                    
                            var $phone = this.$el.find('input[name="phone"]');                
                            var phone = $phone.val();
                            var router = this.getRouter();
                    
                            $.ajax({
                                url: 'Meeting/action/Test',
                                type: 'POST',
                                data: JSON.stringify({
                                    phone: phone
                                }),
                                success: function (data) {
                                    var url;
                                    var router = self.getRouter();                        
                                    url = '#' + 'Meeting' + '/create';
                    
                                    window.location = url;
                                    var attributes = self.getView('edit').fetch();
                                    var model = self.getView('edit').model;
                                    attributes = _.extend(attributes, model.getClonedAttributes());
                    
                                    console.log(model);
                    
                                    self.close();
                                }
                            });
                        }
                    },
                    It gives this error.

                    Uncaught TypeError: Cannot read property 'fetch' of undefined or model.

                    Comment

                    • gundogduyakici
                      Senior Member
                      • Mar 2018
                      • 165

                      #11
                      Do you understand the problem? tanya

                      Comment

                      • mr2d2
                        Senior Member
                        • Apr 2017
                        • 126

                        #12
                        Originally posted by gundogduyakici
                        I am redirecting to the post-Ajax post creation page. After redirecting, I want to auto-fill the name field on the build page with the data I get from ajax. Is this possible ?

                        Code example;
                        Code:
                        $.ajax({
                        url: 'Meeting/action/Test',
                        type: 'POST',
                        data: JSON.stringify({
                        phone: phone
                        }),
                        success: function (data) {
                        if(data.status == 409){
                        console.log("duplicate");
                        }else{
                        // I want auto-fill name field. ?
                        window.location = '#Meeting/create';
                        self.close();
                        }
                        }
                        });
                        Faced the same problem.
                        Can you tell how you solved this problem?

                        Comment

                        Working...