Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jquery - Cannot change button value by ajax

After applying the http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css and http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js

the text of the button cannot be changed by scripting $(this).val('new value');

Do anyone have similar experience and have the solution?

DEMO can be tried from FIDDLE

JQUERY:

$(document).ready(function () {
    $('#submit_btn').click(function (e) {
        e.preventDefault();
        $(this).val('Processing ...');
        $.ajax({
            cache: false,
            type: "POST",
            dataType: "json",
            data: $('#form1').serialize(),
            url: "echo/json",
            complete: function (HttpRequest, textStatus) {
                $(this).val('Create');
            }
        });
        return false;
    });
});

HTML:

<form action="call.php" method="POST" id="form1" name="form1">
    <input type="text" name="campname" id="campname">
    <textarea id="longdesc" name="longdesc"></textarea>
    <input type="text" name="vercode" id="vercode" />
    <input type="submit" value="Create" id="submit_btn" />
</form>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Can you try this,

 $(".ui-btn-text").text('Processing ...');

Code:

$(document).ready(function () {
  $('#submit_btn').click(function (e) {        
    e.preventDefault();
    $(".ui-btn-text").text('Processing ...');
    $.ajax({
        cache: false,
        type: "POST",
        dataType: "json",
        data: $('#form1').serialize(),
        url: "echo/json",
        complete: function (HttpRequest, textStatus) {
           $(".ui-btn-text").text('Create');
        }
    });
    return false;
   });
});

Demo : http://jsfiddle.net/Rz2sJ/4/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...