English 中文(简体)
未能从JSON获得数据
原标题:Not getting data from JSON

我的文字是获得JSON数据:

<script type="text/javascript" src="jquery-1.7.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $( #useruname ).change(function() {
        var userName = $(this).val();
        $.ajax({
            type:  GET ,
            url:  ajaxuseradd.php ,
            data: {
                uname: userName
            },
            success: function(data, status, xhr) {
                $("#fname").val(data.fname);
                $("#lname").val(data.fname);
                $("#email").val(data.email);
                });
            },
            dataType:  json 
        })
    });
});


</script>
<form action="adduser.psp" method="get">
<fieldset>
    <label for="uname">Username:</label>
    <select name="uname" id="useruname">
<%
Random Python Code
%>

<%= options %>

</select>

</fieldset>
<fieldset>
    <label for="fname">First Name:</label>
    <input type="text" name="fname" />
</fieldset>
<fieldset>
    <label for="lname">Last Name:</label>
    <input type="text" name="lname" />
</fieldset>
<fieldset>
    <label for="email">Email:</label>
    <input type="text" name="email">
</fieldset>

我发现的错误如下:

updateAdduser is not defined
onchange()onchange (line 2)
event = change
[Break On This Error] updateAdduser(); 
最佳回答
  1. Your IDs do not match. You have "useruname" in the html and "username" in the jquery bind.

  2. You should delete the onchange attribute in your html - you are calling a function that does not exist (which is where your undefined error comes from) and it would be redundant if it did - just use the .change() you have in script.

问题回答

如果是一部法律,......

Could be the wrong id:

On JS: $( #username ).change(....)

传真:<select name=“uname” id=useruname<<>>>>





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.