我的搜索文字中未知%27。为什么?

时间:2014-04-08 08:26:36

标签: javascript ajax

我有这个数据用于我的ajax参数

data: param ="searchField="+txtSearch+"&office="+localStorage.getItem("office")+"&person="+localStorage.getItem("person")+"&user="+localStorage.getItem("user")+"&organization="+localStorage.getItem("organization"),

在我的地址栏中我得到了

http://msw-wsdl.company.net/mobile.asmx/ContactGet?searchField=%27test&office=97&person=119&user=531&organization=14

如果我取出27%,则查询会根据需要返回数据。

我转向谷歌,我读到这是一个“撇号”,但我不在那里使用。 还有什么可以导致这个?

JavaScript的:

function initContactView() {

    var txtSearch = $("#searchTextField").val();
    $.ajax({
        type: "GET",
        data: param = "searchField="+txtsearch+"&office="+localStorage.getItem("office")+"&person="+localStorage.getItem("person")+"&user="+localStorage.getItem("user")+"&organization="+localStorage.getItem("organization"),
        contentType: "application/json; charset=utf-8",
        url: "http://smw-wsdl.company.net/mobile.asmx/ContactGet",
        dataType: "json",
        success: successContact,
        failure: function (msg) {
            console.log(msg);
        }
    });
} 


/*wsdl call succeed*/
function successContact(data) {
    //apply datasource to listview
    $("#lstView_contacts").kendoMobileListView({
        dataSource: JSON.parse(data.d),
        template: $("#lstView_contact_Template").html(),
        endlessScroll: true,
        scrollThreshold: 8
    });

HTML

<input required='required' class='txt_input' type='text' placeholder="e.g. Cape Town or 244 Jean Avenue or Jhon Doe" id='searchTextField'/>

1 个答案:

答案 0 :(得分:0)

你应该以JSON格式传递GET参数。尝试更改数据参数:

{"searchField":txtsearch,"office":localStorage.getItem("office"),"person":localStorage.getItem("person"),"user":localStorage.getItem("user"),"organization":localStorage.getItem("organization")}