jquery.get从php到另一个输入的结果


jquery.get result from php to another input

我使用以下代码:

$('#inputname').change(function(){ //on change event
            var parentVal = $('#inputname').val(); 
            $.ajax({
                url     : 'file.php',
                type    : 'GET', //type of request, GET or POST
                data: ({ svalue: parentVal }),
                success : function(data){ $('#slug').html(data); }
            });
        });

我想在php中处理后,将在一个文本字段中键入的内容显示到另一个文本域中。在php文件中,我只有一个用于测试目的的echo$_GET['svalue']。

有什么想法吗?非常感谢。

如果是文本字段,请使用.val而不是.html

 $('#slug').val(data);

我有一些可以帮助你的东西要分享。使用地点:

use .html() to operate on containers having html elements.
use .text() to modify text of elements usually having separate open and closing 
            tags

不使用的地方:

.text() method cannot be used on form inputs or scripts.
    .val() for input or textarea elements.
    .html() for value of a script element.
Picking up html content from .text() will convert the html tags into html 
entities.

差异:

.text() can be used in both XML and HTML documents.
.html() is only for html documents.