首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GET请求在urls中未定义

GET请求在urls中未定义
EN

Stack Overflow用户
提问于 2019-08-26 18:10:41
回答 1查看 272关注 0票数 0

我试图从API get调用中获取数据,然后使用补丁调用编辑该数据,但我的get请求似乎在这里不起作用。我是react的新手,任何帮助都会得到重视。我对此还很陌生。但我在网上找不到太多的帮助。这是我的editInvice.js

代码语言:javascript
复制
import {
    Button, Card,
    CardBody,
    CardHeader, Col, Form,
    FormGroup, Input,
    Label, Row,
} from 'reactstrap';
import GooglePlacesAutocomplete from 'react-google-places-autocomplete';
import {editInvoice, getInvoiceDetails} from "../../../helpers/api";


export default () => {

    //
    // var len = window.location.href.length;
    // var id = window.location.href[len-1];


    //TODO THIS IS NOT THE REACT METHOD TO FETCH ID FROM THE URLTT

    const [form, setForm] = useState({
        'id': '',
        'invoice_number': '',
        'invoice_date': '',
        'invoice_due_date': '',
        'invoice_place_of_supply': '',
        'invoice_destination': '',
        'invoice_destination_address': '',
        'invoice_destination_pincode': '',
        'invoice_gst': '',

        'invoice_quiz_id':'',


        'invoice_salesperson': '',
        'invoice_lr_number': '',
        'invoice_vehicle_placement_date': '',
        'invoice_vehicle_number': '',
        'invoice_service_month': '',
        'invoice_item_details': '',

        'invoice_rate': '',
        'invoice_tax': '',
        'invoice_amount': '',
        'invoice_quiz': '',
        'invoice_owner': '',
        'invoice_quantity': '',


        'lr_number': '',
        'billing_party_name': '',
        'origin_address': '',
        'origin_pincode': '',
        'vehicle_placement_date': '',
        'vehicle_number': '',
        'item_details': '',
        'item_quantity': '',
        'total_amount': '',
        'tax': '',

    });


    useEffect(() => {
        const getNetwork = async () => {
            const invoice_details = await getInvoiceDetails(form.invoice_quiz);
            setForm(invoice_details);
        };
        getNetwork();
    }, [setForm]);


    const handleInputChange = (event) => {
        const target = event.target;
        const value = target.type === 'checkbox' ? target.checked : target.value;
        const name = target.name;

        setForm({
            ...form,
            [name]: value
        });
    };

    const handleSubmit = async (event) => {
        event.preventDefault();
        try {
            alert(JSON.stringify(form));
            await editInvoice(form, form.invoice_quiz_id);
            alert('done')
        } catch (e) {
            alert(JSON.stringify(e))
        }
    };

    return (
        <Card>
            <CardHeader>
                <strong>Edit Invoice</strong>
            </CardHeader>
            <CardBody>
                <Form method={'post'} onSubmit={handleSubmit}>
                    <Row form>
                        <Col md={4}>
                            <FormGroup>
                                <Label for="origin">Invoice number</Label>
                                <Input type="text" name="invoice_number" id="invoice_number" valid={form.invoice_number}
                                       onChange={handleInputChange}/>

                            </FormGroup>
                        </Col>

                        <Col md={4}>
                            <FormGroup>
                                <Label for="origin">Invoice ID</Label>
                                <Input type="text" name="id" id="id" value={form.id}
                                       onChange={handleInputChange}/>
                            </FormGroup>

                        </Col>
                        <Col md={4}>
                            <FormGroup>
                                <Label for="scheduled_date">Invoice Date</Label>
                                <Input type="datetime-local" name="invoice_date" id="invoice_date"
                                       value={form.invoice_date}
                                       onChange={handleInputChange}/>
                            </FormGroup>
                        </Col>
                    </Row>
                    <Button color={"primary"} size={"lg"}>Create</Button> &nbsp;&nbsp;&nbsp;
                    <Button color={"link"} size={"lg"}>Cancel</Button>
                </Form>
            </CardBody>
        </Card>

这是我的get API调用:

代码语言:javascript
复制
const GET_INVOICE = '/suppliers/invoiceapi/';
export const getInvoiceDetails = (id) => loadSecureUrl(`${GET_INVOICE}${id}`);

这是我的补丁API调用

代码语言:javascript
复制
const EDIT_INVOICE = 'suppliers/invoiceapi';
export const editInvoice = (data,id) => loadSecureUrl(`${EDIT_INVOICE}${id}`, {
    data: data,
    method: 'patch'
});```
EN

回答 1

Stack Overflow用户

发布于 2019-08-26 18:29:07

我认为您的GET功能中缺少方法。我希望这能回答你的问题。

代码语言:javascript
复制
const GET_INVOICE = '/suppliers/invoiceapi/';
    export const getInvoiceDetails = (id) => loadSecureUrl(`${GET_INVOICE}${id}`, {
    method: 'get'
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57655854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档