对不起乱码。通过alert和console.log工作后,我意识到了
var username = $('#username').value = response2;
将以编程方式填充jquery字段。
$('#signup-button').click(function() {
callTheJsonp();
});
function callTheJsonp()
{
// the url of the script where we send the asynchronous call
var url = "http://localhost:8888/ajax1.php?callback=parseRequest";
// create a new script element
var script = document.createElement('script');
// set the src attribute to that url
script.setAttribute('src', url);
// insert the script in out page
document.getElementsByTagName('head')[0].appendChild(script);
}
function parseRequest(response){
var response1 = response;
var re1='.*?'; // Non-greedy match on filler
var re2='([\\w-+]+(?:\\.[\\w-+]+)*@(?:[\\w-]+\\.)+[a-zA-Z]{2,7})'; // Email Address 1
var p = new RegExp(re1+re2,["i"]);
var m = p.exec(response1);
if (m != null)
{
var response2=m[1];
// document.write(""+email1.replace(/</,"<")+"");
myFunction(response2); //email address from parent without json encode
}
try // try to output this to the javascript console
{
console.log(response2);
}
catch(an_exception) // alert for the users that don't have a javascript console
{
alert('product id ' + response.item_id + ': quantity = ' + response.quantity + ' & price = ' + response.price);
}
}
function myFunction(response2){//how would I populate the jquery objects with the value of response2, just substituting the varaible values breaks the code.
var username = $('#username').val().trim();
var emailAddress = $('#emailAddress').val().trim();
var password1 = $('#password1').val().trim();
var password2 = $('#password2').val().trim();
var postJson = {username: username,
password1: password1,
password2: password2};
if (emailAddress) {
postJson.emailAddress = emailAddress;
}
$('#spinner-container').append('<div id="spinner"><img src="/static/images/progress-spinner.gif" alt="in progress"/></div>');
$.ajax({
type: 'POST',
url: '/signup/',
data: JSON.stringify(postJson),
dataType: 'json',
contentType: 'application/json',
success: function(response) {
window.location.href = '/' + username + '/designs';
},
error: function(response) {
SS.render_errors(JSON.parse(response.responseText));
$('#spinner').remove();
}
});
return false;
}
});
在这一行:
function myFunction(response2){
我想用response2值填充jquery字段,这是一个被剥离成字符串的json对象。任何帮助是极大的赞赏。