开发者

ajax no function after modify jquery script

i want to show some data from DB. and i'm use ajax to do that. But something wrong is happen, the can't show after i have changed some jquery script in my page.

which part of following script that caused my page not show the result:

$("#model").change(function() {
             var barcode;
             barCode=$("#model").val();
             var data1 = $("#model").val(barCode.substr(0,barCode.length-8));
             var data2 = $("#serial").val(barCode.substr(barCode.length-8,8));
             var str= data1;
             var matches=str.match(/[TEJUG2]\D*D/i);
         $.ajax({
                  type:"post",
                  url:"process1.php",
                  data:"tversion="+matches+"&action=tunermatches",
                  cache:false,
                  async:false,
                  success: function(res){
                                 $('#value').replaceWith(
                                           "<div id='value'><h6>" + res + "</h6></div>"
                                           );
                                 }
                  });

what i want to do is after separate some data. the script will read data1 then do some filtering character from text value(use regex).

after match, ajax will send to 开发者_StackOverflow社区DB then filtering data inside DB. after that data will show inside page.


You are doing some strange things with your variables.

Initially, barCode=$("#model").val(); looks reasonable, though you might want to combine it with the definition above.

Then you call var data1 = $("#model").val(barCode.substr(0,barCode.length-8));, so data1 is actually a jQuery object: http://api.jquery.com/val/#val2

So it looks like you are calling val(something) and expecting to get back the string, like if you'd called val(). What you probably want to do is say

var data1 = $("#model").val(barCode.substr(0,barCode.length-8)).val();

Because this will give you the actual value of what's in #model.

In addition, matches is an array, so you probably want to call

data:"tversion="+matches.length+"&action=tunermatches", instead (note the addition of the .length to matches).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜