Php jqueryajax可以';在外部URL上注入时无法工作?

Php jqueryajax可以';在外部URL上注入时无法工作?,php,jquery,ajax,post,jsonp,Php,Jquery,Ajax,Post,Jsonp,我目前正在尝试从图书搜索网站检索一些数据,并用这些数据填充个人数据库。我的想法是在页面上注入必要的jQuery,这样当我看到一个我想在将来返回的标题时,我就可以单击一个cheeckbox,做出必要的附加注释,然后我希望通过AJAX将其提交给一个PHP脚本,然后用适当的标题填充我的MySQL数据库 请务必查看以下图书馆目录示例: // for every book entry, append checkboxes $('.document-frame').append('<p>Choo

我目前正在尝试从图书搜索网站检索一些数据,并用这些数据填充个人数据库。我的想法是在页面上注入必要的jQuery,这样当我看到一个我想在将来返回的标题时,我就可以单击一个cheeckbox,做出必要的附加注释,然后我希望通过AJAX将其提交给一个PHP脚本,然后用适当的标题填充我的MySQL数据库

请务必查看以下图书馆目录示例:

// for every book entry, append checkboxes
$('.document-frame').append('<p>Choose:?<input type="checkbox" class="Jcustom_c"  /></p><p>Serendepity?:<input type="checkbox" class="Jserep" /></p><p>Include snippet?:<input type="checkbox" class="Jsnippet" /></p>');

// append a Submit button at the bottom of the page, and a blank div for feedback upon success in POST-ing the necessary data
$('#resultPage').append('<input id="Justin" class="Jcustom" type="submit"/><div id="Jfeedback"></div>');

// whenever my checkbox is checked, retrieve / "scrape" the necessary book data
$('.Jcustom_c').change(function() {


    if ($(this).is(':checked'))
        {

    var title = $(this).parent().parent().find('.title a').text();
    var author = $(this).parent().parent().find('.authors a').text();
        var publishd = $(this).parent().parent().find('.publisher').text();
    var status = $(this).parent().parent().find('.metadata .summary').text();
    var img_link = $(this).parent().parent().find('img.artwork').attr("src")

            //  create an XML string from that data. Escape "<" and ">", otherwise when we append the string to the browser for feedback, the browser will not render them correctly.   
        var appended = '<div class="Jappended">&lt;item&gt;&lt;title&gt;' + title + '&lt;/title&gt;&lt;author&gt;' + author + '&lt;/author&gt;&lt;publisher_n_edn&gt;' + publishd + '&lt;/publisher_n_edn&gt;&lt;status&gt;' + status + '&lt;/status&gt;&lt;image&gt;' + img_link + '&lt;/image&gt;&lt;serep&gt;N&lt;/serep&gt;&lt;/item&gt;</div>';

// show the string just below the book title. Hence if I "pick" the book from the catalogue, the XML string will show up to confirm my the fact that I "picked" it.
        $(this).parent().parent().append(appended);

        }

// if I uncheck the box, I remove the XML string    
    else {

    $(this).parent().nextAll(".Jappended").remove(appended);
    $(this).parent().prevAll(".Jappended").remove(appended);    
    }

});
db-ajax.php只是:

echo "Success";
我读过这篇文章:,其中提到“由于同源策略,JavaScript目前无法跨域发出直接请求”。这就是我的代码不能在外部页面上工作的原因吗?如果是,我可以做些什么使代码工作,或者我可以采取什么其他方法来实现相同的目标?我有我正在开发的多个图书搜索网站,其中许多没有API,我可以直接从中提取数据

先谢谢你


附言:我也尝试过CG_DEV on的建议,它说$.post可以用jsonp完成,jsonp是用于跨域AJAX的数据类型。结果:在Firebug上,我确实看到了POST请求。但是我的函数回调没有被触发,当至少返回“Success”时,firebug不会注册响应主体。

您可以设置允许跨源资源共享 遵循两个步骤: 从服务器在响应头上设置此

Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:*
//*如果您想为所有源域允许它,或者您也可以指定要允许cors的源域

在客户端,将其添加到您的页面上

$.support.cors = true;

缺点:ie我只是重新审视这个答案。是否只有jscript才能在客户端启用而不是使用jQuery?
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:*
$.support.cors = true;