如何转换此jquery对象

问题描述 投票:-10回答:1

你好我第一次使用jquery库。

jQuery的:

function habdleProductSubmitRequest(event) {
            //no reload page
            event.preventDefault()
var productId = $(this).find('[name="id"]').val();
var productName = $(this).find('[name="name"]').val();
var productPrice = $(this).find('[name="price"]').val();

$.ajax({
    url:'/api/ajaxrest/post' ,
    method: 'POST',
    processData: false,
    contentType:"application/json; charset=utf-8",
    dataType: 'json',
    data: JSON.stringify({
        id: productId,
        name: productName,
        price : productPrice
    }),
    complete: function(result){

        console.debug(result)

        $('#result3').text(result);


    }

})

}

形成

<h2>Add a new task</h2>

<form
        class="datatable__row datatable__row--add"
        method="POST"
        action="http://localhost:8080/v1/task/createTask"
        data-product-add-form=""

>
    <fieldset class="datatable__row-section datatable__row-section--input-section">
        <label class="datatable__input-label">
            Product Id
        </label>
        <input type="text" name="id" placeholder="Insert a task name" th:required="required" />
    </fieldset>
    <fieldset class="datatable__row-section datatable__row-section--input-section">
        <label class="datatable__input-label">
            Task name
        </label>
        <input type="text" name="name" placeholder="Insert a task name" th:required="required" />
    </fieldset>
    <fieldset class="datatable__row-section datatable__row-section--input-section">
        <label class="datatable__input-label">
            Task content
        </label>
        <textarea name="price" placeholder="Insert task content" th:required="required"></textarea>
    </fieldset>

    <fieldset class="datatable__row-section datatable__row-section--button-section">
        <button type="submit" data-task-add-button="" class="datatable__button">Add a task</button>
    </fieldset>
</form>

<fieldset>
    <span id="result3"></span>
</fieldset>

我不知道如何显示这个返回的对象。此功能不会在此对象的视图中显示我

$('#result3').text(object);

我试过了:

$('#result3').text(object.name + object.price);

但什么也没显示。所以我使用console.debugger qazxsw poi检查了这个对象

javascript jquery
1个回答
0
投票

and here is a screenshot上没有nameprice。它在你的屏幕截图上这么说。然而,objectresponseJSONname。那么为什么不使用那些呢? (我还在两者之间添加了空格,但你应该根据自己的喜好/需要格式化)

price
© www.soinside.com 2019 - 2024. All rights reserved.