Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从输入到函数的敲除发送值_Javascript_Html_Asp.net Mvc 4_Knockout.js_Asp.net Web Api - Fatal编程技术网

Javascript 从输入到函数的敲除发送值

Javascript 从输入到函数的敲除发送值,javascript,html,asp.net-mvc-4,knockout.js,asp.net-web-api,Javascript,Html,Asp.net Mvc 4,Knockout.js,Asp.net Web Api,我有一个文本框和一个按钮,我想在单击按钮时将文本框中的值发送到一个函数,但似乎无法理解 Reg:<input type="text" placeholder="Enter Reg" data-bind="text: search" /> <button class="btn btn-danger" data-bind="click: function () { GJobs(search) }" >Get Jobs</button> ajax调

我有一个文本框和一个按钮,我想在单击按钮时将文本框中的值发送到一个函数,但似乎无法理解

      Reg:<input type="text" placeholder="Enter Reg" data-bind="text: search"  />
<button  class="btn btn-danger" data-bind="click: function () { GJobs(search) }" >Get Jobs</button>
ajax调用

   function GetJobs(search) {
        $.ajax({
            type: "GET",
            url: 'api/mechanicphone',
            data: { reg: search},
            dataType: 'json',
            contentType: 'application/json',
            success: function (data) {
                self.Jobs(data);
            },
            error: function (data) {
                $('#MechMobile').html('<h3>Error in retrieval</h3>');
            }
        });
    }
函数获取作业(搜索){
$.ajax({
键入:“获取”,
url:'api/mechanicphone',
数据:{reg:search},
数据类型:“json”,
contentType:'应用程序/json',
成功:功能(数据){
自助作业(数据);
},
错误:函数(数据){
$('#MechMobile').html('检索错误');
}
});
}

当我调试时,传递的reg在get上为空

您的代码中有一些内容需要更改

首先,为了从输入字段返回值,应使用
绑定而不是`文本:

<input type="text" placeholder="Enter Reg" data-bind="value: search"  />
您的视图模型如下所示:

Reg:<input type="text" placeholder="Enter Reg" data-bind="value: search"  />
<button  class="btn btn-danger" data-bind="click: GJobs" >Get Jobs</button>
self.GJobs = function () {
    GetJobs(self.search());
}
self.search = ko.observable('');
function GetJobs(searchValue){
    // Call web service
}
self.GJobs = function () {
    GetJobs(self.search());
}
self.search = ko.observable('');
function GetJobs(searchValue){
    // Call web service
}