Tag: Ajax

通过AJAX请求重新绘制基于用户input的谷歌图表

我有一个谷歌图表从我的数据库中提取数据,按照我的要求工作。 根据URL中的获取请求,它从选定的表中绘制数据。 我希望通过基于选定表格的下拉菜单中的ajax进行图表更新。 我无法突破的部分是通过ajax获得数据响应。 我认为下面的代码是接近的,但我得到了我似乎无法摆脱的下面的错误。 getdata.php:22 Uncaught ReferenceError:$ is not defineddrawvisualization @ getdata.php:22onchange @ getdata.php:47 我试图从getdata.php中删除GET请求,并认为这是$未定义的硬编码表,但是这并没有解决错误。 工作图代码 <!DOCTYPE> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> Wind Graph </title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['corechart']}); </script> <script type="text/javascript"> function drawVisualization() { var data = new google.visualization.DataTable(); <?php require("dbconnect.php"); echo " data.addColumn('string', 'Time');"; echo […]

asynchronous加载脚本

我正在使用几个插件,自定义窗口小部件和一些JQuery的其他库。 结果我有几个.js和.css文件。 我需要为我的网站创build一个加载器,因为它需要一些时间来加载。 如果我可以在导入所有内容之前显示加载器,那将会很好: <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/javascript" src="js/myFunctions.js"></script> <link type="text/css" href="css/main.css" rel="stylesheet" /> … …. etc 我find了几个教程,使我能够asynchronous导入JavaScript库。 例如我可以做一些事情: (function () { var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'js/jquery-ui-1.8.16.custom.min.js'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); })(); 由于某种原因,当我做所有我的文件相同的事情页面不起作用。 我一直在努力尝试找出问题所在,但我找不到它。 首先,我认为这可能是因为一些JavaScriptfunction依赖于其他人。 但我用正确的顺序使用超时函数加载,当一个完成我进行下一个和页面仍然performance怪异。 例如我不能点击链接等…animation仍然工作虽然.. 无论如何 这是我一直在想…我相信浏览器有一个caching,这就是为什么它需要很长时间才能第一次加载页面,并在下一次快速。 所以我想做的是用一个页面replace我的index.html页面,asynchronous加载所有这些文件。 当ajax完成加载所有这些文件redirect到我打算使用的页面。 当使用该页面时,不应该花很长时间才能加载,因为文件应该被包含在浏览器的caching中。 在我的索引页(.js和.css文件asynchronous加载的页面)我不在乎得到错误。 我将只显示一个加载器,并在完成时redirect页面… […]

如何绕过Access-Control-Allow-Origin?

我在他们设置的平台上对我自己的服务器进行ajax调用,以防止这些ajax调用(但是我需要它从我的服务器获取数据以显示从我的服务器数据库中检索到的数据)。 我的ajax脚本正在工作,它可以将数据发送到我的服务器的PHP脚本,让它来处理。 但是,由于"Access-Control-Allow-Origin"被阻止,因此无法获取已处理的数据。 我无法访问该平台的源代码/核心。 所以我不能删除不允许我这样做的脚本。 (P / SI使用Google Chrome的控制台,发现这个错误) Ajax代码如下所示: $.ajax({ type: "GET", url: "http://example.com/retrieve.php", data: "id=" + id + "&url=" + url, dataType: 'json', cache: false, success: function(data) { var friend = data[1]; var blog = data[2]; $('#user').html("<b>Friends: </b>"+friend+"<b><br> Blogs: </b>"+blog); } }); 还是有一个JSON等效的代码上面的ajax脚本? 我认为JSON是允许的。 我希望有人能帮助我。

Ajax,后退button和DOM更新

如果JavaScript修改了页面A中的DOM,用户导航到页面B,然后点击返回button返回到页面A.对页面A的DOM的所有修改都将丢失,并向用户显示最初从服务器检索到的版本。 它在stackoverflow,reddit和许多其他受欢迎的网站上以这种方式工作。 (尝试添加testing评论到这个问题,然后导航到不同的页面,并回击button回来 – 你的评论将“消失”) 这是有道理的,但一些网站(apple.com,basecamphq.com等)在某种程度上迫使浏览器为用户提供最新的页面状态。 (去http://www.apple.com/ca/search/?q=ipod ,点击顶部的说下载链接,然后点击返回button – 所有的DOM更新将被保留) 哪里来的不一致?

如何使用jQuery生成一个简单的popup窗口

我正在devise一个网页。 当我们点击div命名邮件的内容时,如何显示包含标签电子邮件和文本框的popup窗口?

json未捕获的SyntaxError:意外的标记:

尝试拨打电话并检索一个非常简单的一行JSON文件。 $(document).ready(function() { jQuery.ajax({ type: 'GET', url: 'http://wncrunners.com/admin/colors.json' , dataType: 'jsonp', success: function(data) { alert('success'); } }); });//end document.ready 这是RAW请求: GET http://wncrunners.com/admin/colors.json?callback=jQuery16406345664265099913_1319854793396&_=1319854793399 HTTP/1.1 Host: wncrunners.com Connection: keep-alive Cache-Control: max-age=0 User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.106 Safari/535.2 Accept: */* Referer: http://localhost:8888/jquery/Test.html Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 这是RAW响应: HTTP/1.1 200 OK Date: […]

jQuery在通过AJAX加载内容后不起作用

在这个页面上,我有一个jQuerypopup窗口和缩略图可resize的图像。 如果将鼠标hover在缩略图上,图像的大小将会完美调整。 此外,当我点击页脚中的大黄色电视button“QuickBook TV”时,popup窗口会完全按照我的意愿显示。 但是,当我点击“下一步”或“上一步”button时,使用AJAX加载新的内容,我的jQuery不再适用于popup窗口或缩略图图像。 我已经search了一些论坛寻找关于这个问题的信息,但由于有限的jQuery知识,我一直无法理解我需要做什么。 以下是popup式jQuery $(document).ready(function() { $(".iframe").colorbox({ iframe: true, width: "1000px", height: "500px" }); $(".inline").colorbox({ inline: true, width: "50%" }); $(".callbacks").colorbox({ onOpen: function() { alert('onOpen: colorbox is about to open'); }, onLoad: function() { alert('onLoad: colorbox has started to load the targeted content'); }, onComplete: function() { alert('onComplete: colorbox has displayed the […]

POST JSON失败,415不支持的媒体types,Spring 3 mvc

我想发送一个POST请求到一个servlet。 请求通过jQuery以这种方式发送: var productCategory = new Object(); productCategory.idProductCategory = 1; productCategory.description = "Descrizione2"; newCategory(productCategory); newCategory在哪里 function newCategory(productCategory) { $.postJSON("ajax/newproductcategory", productCategory, function( idProductCategory) { console.debug("Inserted: " + idProductCategory); }); } 和postJSON是 $.postJSON = function(url, data, callback) { return jQuery.ajax({ 'type': 'POST', 'url': url, 'contentType': 'application/json', 'data': JSON.stringify(data), 'dataType': 'json', 'success': callback }); }; 用萤火虫,我看到JSON发送正确: {"idProductCategory":1,"description":"Descrizione2"} 但是我得到415不支持的媒体types。 […]

CORS:当凭证标志为true时,不能在Access-Control-Allow-Origin中使用通配符

我有一个设置涉及 前端服务器(Node.js,domain:localhost:3000)<—>后端(Django,Ajax,域名:localhost:8000) 浏览器< – webapp < – Node.js(服务应用程序) 浏览器(webapp) – > Ajax – > Django(服务ajax POST请求) 现在,我的问题在于CORS设置,Web应用程序使用Ajax调用后端服务器。 在铬,我不断得到 当凭证标志为真时,不能在Access-Control-Allow-Origin中使用通配符。 也不能在Firefox上工作。 我的Node.js设置是: var allowCrossDomain = function(req, res, next) { res.header('Access-Control-Allow-Origin', 'http://localhost:8000/'); res.header('Access-Control-Allow-Credentials', true); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); next(); }; 在Django中,我正在使用这个中间件 Web应用程序提出请求: $.ajax({ type: "POST", url: 'http://localhost:8000/blah', data: {}, xhrFields: { withCredentials: true }, […]

确定$ .ajax错误是否超时

我正在利用jQuery.ajax( settings )的魔力。 不过,我想知道是否有人玩超时设置? 我知道这基本上是为了指定请求的本地时间,但是如果达到超时,它可以触发任何事情吗? 还是只是停止听回应? 阅读jQuery网站,我可以看到没有任何parameter passing,所以它看起来像一个简单的设置function。 这很好。 但是,如果达到超时,我想触发警报或某个function。 在这种情况下,我可以看到错误设置没有被触发。 这是我的片段: $("form#testform").submit(function(){ var allFormValues = $("form#testform").serialize(); $.ajax({ cache:false, timeout:8000, // I chose 8 secs for kicks type:"POST", url:"someurl.php", data:allFormValues, error:function(){ alert("some error occurred") }, success:function(response){ alert(response); } }); }); 有没有人知道如何超时工作?