Click here to Skip to main content
15,891,184 members
Home / Discussions / Web Development
   

Web Development

 
AnswerRe: CGI in Java - Legacy but interesting (for educational purposes) Pin
Trak4Net21-Jul-12 11:22
Trak4Net21-Jul-12 11:22 
QuestionContact me Web page Pin
flinchy319-Jul-12 4:51
flinchy319-Jul-12 4:51 
AnswerRe: Contact me Web page Pin
R. Giskard Reventlov19-Jul-12 5:38
R. Giskard Reventlov19-Jul-12 5:38 
GeneralRe: Contact me Web page Pin
flinchy324-Jul-12 3:06
flinchy324-Jul-12 3:06 
GeneralRe: Contact me Web page Need Help Pin
flinchy326-Jul-12 4:35
flinchy326-Jul-12 4:35 
QuestionInner Exception while creating an instance of java web service in .net client Pin
Anuradhaanu18-Jul-12 19:01
Anuradhaanu18-Jul-12 19:01 
AnswerRe: Inner Exception while creating an instance of java web service in .net client Pin
Sandeep Mewara18-Jul-12 19:52
mveSandeep Mewara18-Jul-12 19:52 
QuestionRebinding Problem with Jquery knockout.js with MVC Pin
Vimalsoft(Pty) Ltd18-Jul-12 5:08
professionalVimalsoft(Pty) Ltd18-Jul-12 5:08 
Good Day Guys

This is an MVC , JQuery, KNockout.js Question.

i have a Controller Action that is being Defined like this

C#
[HttpGet]
        public JsonResult SearchCars(string searchString)
        {

            string[] searchTerms = (searchString).ToUpper().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            string[] searchTermSounds = new string[searchTerms.Length];
 
            var list = (from r in Cache.CarSearchItems
                       select new Lightstone.UI.Web.LaceWebUI.Models.CarItem(r, searchTerms, searchTermSounds)).ToList();

            var list1 = list.Distinct()
                             .Take(5)
                             .OrderByDescending(l => l.Hits).ToList();

            return Json(list1, JsonRequestBehavior.AllowGet);
        } 



and i have a Jquery function that gets fired onkey up event is fired in a textbox like this


JavaScript
$(function () {
    $("#txtSearchString").keyup(function () {

        $("#txtSearchString").queue(function 
            () {
            var _this = $(this);
            _this.addClass("newcolor");
            _this.dequeue();
        });


        if ($("#txtSearchString").val().length >= 3) {
            var data = {}
            data.searchString = $("#txtSearchString").val();
            alert("Retrieving Data");
        
            $.getJSON("/Cars/SearchCars", data, function (result) {
                //Autocomplete binding
                var viewModel = null;

                viewModel =
                 { 
                     SearchOptions: ko.observableArray(result) // These are the initial options 
                 }
                alert("Done Retrieving Data");

                if (viewModel == null || viewModel == undefined) {
                    alert("The ViewModel is null or Undefined");
                 
                    alert("Done with the View Model");
                }
                else {
                    ko.applyBindings(viewModel);
                    alert("THe View Model is no Null");
                }
              


            });

        }

    })
}); 

dont mind my alerts i use them to check the code reaches the place that i want it to reach. I can get the Jason the first time and this is the order of my alerts

JavaScript
 alert("Retrieving Data");
 alert("Done Retrieving Data");
alert("THe View Model is no Null");



and then i bind the data to my HTML view as depicted below


C#
<table  id="tblsearchresults"  data-bind="foreach:SearchOptions"  class="auto-style1">
        <tr>
            <td rowspan="5">
                <img data-bind="attr: {src: Url}" class="" />
            </td>
            <td>Make:</td>
            <td>
                <div data-bind="text: Make">
                </div>
            </td>
            <td> </td>
        </tr>
        <tr>
            <td>Model:</td>
            <td>
                <div data-bind="text: Model">
                </div>
            </td>
            <td> </td>
        </tr>
        <tr>
            <td>Year:</td>
            <td>
                <div data-bind="text: Year">
                </div>
            </td>
            <td> <a data-bind="attr: { href: UrlRedirect }">
                View Report</a>

            </td>
        </tr>
        <tr>
            <td> </td>
            <td> </td>
            <td> </td>
        </tr>
        <tr>
            <td> </td>
            <td> </td>
            <td> </td>
        </tr>
    </table>



and i see the data when i search for the first time and the images appears nicely and then the Problem start when i change my search string lets say i now type "FORD"

C#
<input id="txtSearchString" name="txtSearchString" class="searchText" />


and it does not return results, when i look at the F12 debugging tool in chrome it point to my JavaScript in the following line

C#
ko.applyBindings(viewModel); 


and in my

C#
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 knockout-2.1.0.js:46
a.e.Fa knockout-2.1.0.js:46
a.a.Oa knockout-2.1.0.js:81
a.Fb.a.h.disposeWhenNodeIsRemoved knockout-2.1.0.js:75
e knockout-2.1.0.js:34
a.h knockout-2.1.0.js:36
a.Fb knockout-2.1.0.js:75
a.c.template.update knockout-2.1.0.js:76
a.c.foreach.update knockout-2.1.0.js:66
a.h.disposeWhenNodeIsRemoved knockout-2.1.0.js:51
e knockout-2.1.0.js:34
a.h knockout-2.1.0.js:36
d knockout-2.1.0.js:49
c knockout-2.1.0.js:49
b knockout-2.1.0.js:49
c knockout-2.1.0.js:49
b knockout-2.1.0.js:49
c knockout-2.1.0.js:49
b knockout-2.1.0.js:49
c knockout-2.1.0.js:49
b knockout-2.1.0.js:49
c knockout-2.1.0.js:49
b knockout-2.1.0.js:49
c knockout-2.1.0.js:49
a.xa knockout-2.1.0.js:52
(anonymous function) AutoCompleteResults.js:33
jQuery.Callbacks.fire jquery-1.7.2.js:1075
jQuery.Callbacks.self.fireWith jquery-1.7.2.js:1193
done jquery-1.7.2.js:7538
jQuery.ajaxTransport.send.callback jquery-1.7.2.js:8324



So everytime i do my search for the first time it works but for the second time it does not.

One other solution that i need is to delay the call of the keypress for 250 milliseconds.

Thanks
Vuyiswa Maseko,

Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.

C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa[at]dotnetfunda.com
http://www.Dotnetfunda.com

AnswerRe: Rebinding Problem with Jquery knockout.js with MVC Pin
Vimalsoft(Pty) Ltd18-Jul-12 22:37
professionalVimalsoft(Pty) Ltd18-Jul-12 22:37 
Generalinstance of a soap web service not creating Pin
Anuradhaanu18-Jul-12 2:40
Anuradhaanu18-Jul-12 2:40 
Questionjava soap webservice and .net client validating service using soap headers Pin
Anuradhaanu17-Jul-12 18:42
Anuradhaanu17-Jul-12 18:42 
SuggestionRe: java soap webservice and .net client validating service using soap headers - Repost Pin
Richard MacCutchan17-Jul-12 21:54
mveRichard MacCutchan17-Jul-12 21:54 
Questiontracing Pin
hossam jarrah16-Jul-12 23:18
hossam jarrah16-Jul-12 23:18 
GeneralRe: tracing Pin
Sandeep Mewara16-Jul-12 23:33
mveSandeep Mewara16-Jul-12 23:33 
GeneralRe: tracing Pin
Albert Holguin18-Jul-12 16:03
professionalAlbert Holguin18-Jul-12 16:03 
QuestionHow to Bind Data with Knockout Pin
Vimalsoft(Pty) Ltd16-Jul-12 7:22
professionalVimalsoft(Pty) Ltd16-Jul-12 7:22 
QuestionREST and WCF Pin
Xarzu15-Jul-12 20:34
Xarzu15-Jul-12 20:34 
QuestionSystem.Web.UI.WebControls.FileUpload Pin
sheemap12-Jul-12 20:41
sheemap12-Jul-12 20:41 
AnswerRe: System.Web.UI.WebControls.FileUpload Pin
Richard MacCutchan12-Jul-12 22:11
mveRichard MacCutchan12-Jul-12 22:11 
AnswerRe: System.Web.UI.WebControls.FileUpload Pin
Sandeep Mewara12-Jul-12 23:12
mveSandeep Mewara12-Jul-12 23:12 
QuestionAutomatic Login to Another Domain Pin
Kyudos11-Jul-12 15:31
Kyudos11-Jul-12 15:31 
QuestionGridView preselectfirstrow and move to the next after button click event Pin
byka11-Jul-12 2:53
byka11-Jul-12 2:53 
Generalerror at download files in php Pin
Member 915215611-Jul-12 2:43
Member 915215611-Jul-12 2:43 
QuestionCaching html pages - no thanks - but how? Pin
lvq68410-Jul-12 20:11
lvq68410-Jul-12 20:11 
AnswerRe: Caching html pages - no thanks - but how? Pin
Gerben Jongerius10-Jul-12 23:22
Gerben Jongerius10-Jul-12 23:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.