角4:通过POST服务从表元素保存变量 [英] Angular 4: Saving variable from the table element through POST service

查看:74
本文介绍了角4:通过POST服务从表元素保存变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular的新手,我需要帮助通过POST服务保存表中的值.下面是我的代码.

I am new to Angular and I need help in saving the value from a table through a POST service. Below is my code.

saveCalendar(value: any) {
  console.log("Updated Value"+ value); // value from the table
  this.body = {
  "promotionname": this.promotionname,
  "period": this.period,
  "indicator": this.indicator,
  "value": this.value
};
this.services.saveCalendar(this.body)
.then(
 response => {
   if(response == "Success")
     {
       this.firstPage(this.clickedItem);
     }
 }
);

}

服务:

 saveCalendar(body: object): Promise<any> {

                return this.http.post(environment.serverUrl+'/api/update_promocal', body)
                  .toPromise()
                  .then(
                     response => {
                      if(response['_body'] == "Save Successful!")
                        {
                          return "Success";
                        }
                    } 

                  )
                  .catch(error => console.log('Error while getting response: '+error))
              }

以下是来自后端的服务:

Below is the service from the backend:

def update_promocal(request):

id1 = request.GET.get('id')
column = request.GET.get('column')
data = request.GET.get('data')

test = Promocal.objects.get(id = id1)

if column == 'promotionname':

    test.promotion_name = data

elif column == 'period':

    test.period = data

elif column == 'indicator':

    test.indicator = data

elif column == 'value':

    test.value = data

elif column == 'marketdriver':

    test.market_driver = data

else:

    test.save()




test.save()

我想通过POST方法将此更新的值发送回服务,以便可以将其保存在数据库中.但是我遗漏了一些东西.请在这里帮助.

I want to send this updated value back to the service via POST method so that it can be saved in the database.But I am missing out something. Please help here.

推荐答案

我发现了这一点,我对python的经验有限吗?希望这行得通:def do_POST():#对发布的数据不做任何事情content_length = int(self.headers ['Content-Length'])#< ---获取数据的大小post_data = self.rfile.read(content_length)#< ---获取数据本身self._set_headers()self.wfile.write("

POST!

")以上是您用来捕获Post请求的所有内容吗?

I found this bit, I have limited experiemce with python? Hopefully this works: def do_POST(self): # Doesn't do anything with posted data content_length = int(self.headers['Content-Length']) # <--- Gets the size of data post_data = self.rfile.read(content_length) # <--- Gets the data itself self._set_headers() self.wfile.write("

POST!

") Is the above everything you are using to catch the Post request?

403是一个禁止的错误,表示您没有index.html或没有访问Web服务器的权限.

403 is a forbidden error, indicating you either have no index.html or no permission to access the webserver.

您的网络服务器在本地吗?在邮递员中,您使用的是正确的地址,即您使用的端口是否错误?服务器正在侦听哪个端口,并且您正在使用该端口?

Is your webserver local? In postman are you using the right address, ie could it be you use the wrong port? What port is you server listening to and are you using that port?

这篇关于角4:通过POST服务从表元素保存变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆