2

I am pretty good with Coldfusion and passing variables in forms through the web via URL. I cannot wrap my head around this mobile stuff yet. I am developing an app that pulls from a database on my server. I have 2 calls to the server now that just pulls data without any "where" statement and they work great. I want to add a search input that will have what the user types in the box to go in my query on my .cfc. Not sure how to pass that data from the phone form to the cfc on my server.

Here's the search button code...

<form action="searchresult.html" method="post"  data-transition="none">
    <input type="search" name="mySearch" 
           id="mySearch" value="" data-mini="true" data-theme="b" />
</form>

This is my script code in XCode that should run when the search is submitted...(i don't know where to put any variable to pass to the cfc. Can it be passed in the URL?)

$("#resultPage").live("pageshow", function() {
    console.log("Getting remote list" + event.notification);
    $.mobile.showPageLoadingMsg();
    $.get("http://www.mywebsite.com/jquery/ryprad.cfc?
                      method=getsearch&returnformat=json", 
        {}, 
        function(res) {
            $.mobile.hidePageLoadingMsg();
            var s = "";
            for(var i=0; i<res.length; i++) {
                s+= "<li><a name=" + res[i].id + " + href='" 
                    + res[i].showlink + "'>" 
                    + res[i].date + "<br/>" + res[i].name + "<br/>" 
                    + res[i].description + "</a></li>";
            }

            $("#resultList").html(s);
            $("#resultList").listview("refresh");
            },
        "json"
    );
});

And this is my cfc on the server...

component {
remote array function getsearch() {
    var q = new com.adobe.coldfusion.query();
        q.setDatasource("myDat");
        q.setSQL("
            select id1, Date, ShowLInk, IntName, description from RYPRadio 
            Where intName 
            LIKE '%#VARIABLE_FROM_PHONE_SEARCH#%' 
            order by date desc"
        );
        var data = q.execute().getResult();
        var result = [];
        for(var i=1; i<= data.recordCount; i++) {
            arrayAppend(
                result, 
                {
                    "id"=data.id1[i], 
                    "name"=data.IntName[i], 
                    "date"=dateformat(data.date[i], "mmmm d, yyyy"), 
                    "description"=data.description[i], 
                    "showlink"=data.ShowLInk[i]
                }
            );
        }
        return result;
    }
}

I hope someone can help with this. If I can get this working, it will help me develop other things that will pass variables such as this!

4

2 に答える 2

6

検索文字列を jquery 呼び出しに追加します。

$.get("http://www.mywebsite.com/jquery/ryprad.cfc?method=getsearch&returnformat=json&searchName="+ $("#mySearch").val(), {}, function(res) {

ColdFusion で引数を追加します。

remote array function getsearch( searchName ) {

それに応じてクエリを調整します。これには、次のようにパラメーターを使用する必要があります。

q.setSQL("select id1, Date, ShowLInk, IntName, description from RYPRadio Where intName LIKE :searchParam order by date desc");
q.addParam( name="searchParam", value="%#searchName#%" );
于 2012-07-05T21:25:09.320 に答える
0

このような意味ですか:http://jacktraynor.blogspot.com.au/2012/02/jquery-autocomplete-using-coldfusion.html ?m = 1

于 2012-07-05T21:22:05.900 に答える