Tag: ajax

将所选值传递给jQuery的select2 ajax调用

我正在尝试将多个参数(所选值)传递给multiple select2的ajax调用: $(“#ddlMultiCourse”).select2({ placeholder: “Search for Course”, minimumInputLength: 1, allowClear: true, ajax: { // instead of writing the function to execute the request we use Select2’s convenient helper url: url,//GetCourseList type: “POST”, dataType: ‘json’, delay: 250, data: function (params) { return { term: params.term, // search term value: $(“#ddlMultiCourse”).val()//extra parameter }; }, processResults: function (data, […]

如何添加AJAX提交到PHPvalidation并返回消息?

我一直在努力validation表单,并使JS和PHPvalidation工作,但我仍然很难添加ajax(有或没有JQUERY)提交到php文件并返回成功消息。 我的表单有CSS和JSvalidation: #nameerror { color:red; } #emailerror{ color:red; } function Validate() { var email = document.forms[‘form’][’email’].value; var atpos = email.indexOf(‘@’); var dotpos = email.lastIndexOf(‘.’); var name = document.forms[‘form’][‘name’].value; if (name == null || name == “”){ document.getElementById(‘nameerror’).innerHTML=”Please enter your name”; return false; } else if (atpos < 1 || dotpos = email.length) { document.getElementById(’emailerror’).innerHTML=”Please enter […]

AJAX和JS for LIKE Button

我正在尝试学习如何在我的网站上为LIKE按钮制作一个AJAX脚本。 我有以下问题: 如果我发送1变量…. id ..我这样做 data: “action=vote_up&id=”+(this).attr(“id”)”, 如果我发送两个变量id和id1,这在语法上是否正确? data: “action=vote_up&id=”+(this).attr(“id”)&id1=”+(this).attr(“id1″)”, 2)什么进入href属性? php页面还是AJAX? 3)首先运行.. php页面或AJAX。 4)我是否必须使用jQuery或Pure Javascript来运行AJAX 感谢您的时间和耐心。 我最欣赏它。

jquery ajax选项卡在单击后更改为“正在加载…”

在以下代码中,所有选项卡最初都会显示其正确的文本(主页,报告,设置,文档,支持)。 单击任何ajax选项卡(主页,文档,支持)时,选项卡上的文本将更改为“正在加载…”。 但是,2个非ajax选项卡(Reports和Setup)保留其文本。 如何防止“加载……”为什么会改变? $(document).ready(function() { $(“#tabs”).tabs(); }); $(document).ready(function() { $(“#tabs”).tabs({ ajaxOptions: {cache: false}}); } Home Reports Setup Documentation Support

无法在$ .post函数中设置变量

我试图设置一个计数器到我的jquery ajax post函数返回。 我想要做的是确定后端是否返回任何内容。 所以我试着计算每个函数运行的次数,但是在post函数完成之后,i被设置回零。 但在中间,我运作正常。 为什么会这样? 如何检查响应是否为空? i=0; $.post(url, data, function(resp) { $(‘form’).find(‘.errors’).remove(); $.each(resp, function(index, value) { $(“#” + index).parent().append(getErrorHtml(value, index)); i++; c.log(i); }); }, ‘json’); c.log(i); 谢谢! 可以使Ajax请求同步帮助吗? $.ajaxSetup({async:false});

只有加载表中的最后一个AJAX请求排序

对于这个问题,我创建了以下示例解决方案: http : //jsfiddle.net/PKcnb/3/ 。 该代码通过YouTube API请求50个video(由于请求限制)。 每个请求都会在最终表中附加一个新行。 我想要一个简单的排序解决方案,所以我使用了jquery.sortElements.js。 sortElement.js似乎可以工作,但它只是对上次发出的请求中的video进行排序。 为什么整个表没有排序? 搜索一下,看起来我需要实现.live(),但我的尝试都没有成功。 相关的JQuery // Recursive function to grab the next set of videos function getVideos(index, max) { $.ajax({ url: ‘https://gdata.youtube.com/feeds/api/playlists/UUAuUUnT6oDeKwE6v1NGQxug?v=2&orderby=duration&max-results=50&start-index=’ + index, // ‘https://gdata.youtube.com/feeds/api/users/tedtalksdirector/uploads’, dataType: “xml”, success: function(xml) { var videos = $(xml).find(“entry”); videos.each(function() { var title = $(this).find(“title”).text(); var duration = $(this).find(“duration”).attr(“seconds”); var minutes […]

AJAX JSONP调用时执行时间重叠

我有一个jsonp ajax调用,它被执行并将数据返回给我的main函数。 这是通过调用that.mainfunction(newData);在success函数中完成的that.mainfunction(newData); 这意味着第二次调用main函数,我认为我正在运行时间/执行问题。 在第一次迭代中运行时, newData为空,并返回空主函数。 我必须使用这个框架的主要function。 所以另一个控件试图调用空的getter。 因此控制是空的。 然后第二次迭代开始。 数据在这里,脚本调用that.mainfunction(newData); 并将数据返回到main函数。 但 第二次迭代运行的时间太晚,无法将数据传输到控件。 因为它已经尝试获取数据。 如何避免这个时间/执行问题? 在使用jquery时是否可以发布/订阅一些事件总线? 这是一些代码: sap.designstudio.sdk.Component.subclass(“component”, function() { var that = this; this.processDataFromServer = function(){ function getData(callback){ $.ajax({ url: path, dataType: ‘jsonp’, contentType: “application/json”, success: function(data){ callback(data); } }); }; getData(processData); function processData(data){ this.processDataFromServer(data); }; } this.mainFunction = function(newValue){ if(typeOf(newValue) == “undefined”{ […]

Ajax调用无法在onbeforeunload事件中工作

我有一些function,我需要在使用浏览器的“X”按钮关闭浏览器之前进行ajax调用以更新数据库值。 我在相关文件的标题中使用了以下代码: $(document).ready(function() { window.onbeforeunload = function(){ $.ajax(‘index.php/ajax/myfunction?a=4’); } }); 关闭浏览器时,该function有效,但不执行ajax调用。 解决方案是什么?

HTTP错误405.0 – 使用Jquery ajax get不允许使用方法

我正在开发一个用户必须插入用户名的表单。 我想查看用户的用户名有效的模糊: 我添加了这个脚本: 在HTML中: 脚本: function checkUsername(){ var usn = document.getElementsByName(‘username’)[0]; if(usn.value != “”) { var html = $.ajax({ type: “GET”, url: “checkUsername.php?”, data: “usr=” +usr.value async: false, dataType: “text”}).responseText; if(html == “si”) { usn.style.backgroundColor = “green”; } else { usn.style.backgroundColor = “red”; usn.value = “Username still exists!”; } } } 因此onBlur不起作用,当我提交表单时,它看起来像这样的错误: HTTP Error 405.0 […]

window.onbeforeunload用于发送数据的替代方法?

下面的AJAX函数访问我的PHP脚本。 目的是在用户关闭页面时删除空白的MySQL条目。 window.onbeforeunload实现这一目标非常完美,但在最新版本的Chrome中,它似乎只允许运行警报。 想知道这种方法是否有任何可比的替代方案? 代码示例(在Chrome中无效): window.onbeforeunload = function() { saveFormData(); return null; } function saveFormData() { $.post(“”, { resume_id: “session->userdata(‘resume_id’); ?>” } ); }