这是我在 www.domain-a.de/external.search.js 上的代码。我从 www.domain-b.de/test.php 调用它:
(function ($) {
// make the ajax request
$.getJSON('http://www.domain-a.de/external-search.js?jsoncallback=?', function(data) {
// append the form to the container
$('#embedded_search').append(data);
$('#embedded_search form').attr('action','');
myUrl = 'http://www.domain-a.de/get-form-values?jsoncallback=?'
var frm = $('#embedded_search form');
// click on submit button
frm.submit(function (ev) {
$.getJSON( myUrl )
.done(function( json ) {
console.log( "JSON Data: " + json );
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
});
});
});
})(jQuery);
运行此代码后,我在控制台中没有收到任何消息。该代码有什么问题?
最佳答案
frm.submit(function (ev) {
ev.preventDefault();
.....rest of code.
关于javascript - 提交表单后 AJAX 调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33647921/