Tag: ajax

Jquery getJSON填充选择菜单问题

我正在使用getJSON填充选择菜单。 我想知道是否有一种方法可以使用jQuery的.each函数来引入这些值? 当然必须有一种更简单的方法来完成这个……也许吧? PHP文件: query($queryMonth); while($rowMonth = $db->fetch_assoc($result)) : $data[] = $rowMonth; endwhile; echo json_encode($data); ?> jQuery: $.getJSON(‘selectMenus.php’, function(data){ $(“select.month”).append(“” + data[0].month + “”); $(“select.month”).append(“” + data[1].month + “”); $(“select.month”).append(“” + data[2].month + “”); $(“select.month”).append(“” + data[3].month + “”); $(“select.month”).append(“” + data[4].month + “”); $(“select.month”).append(“” + data[5].month + “”); $(“select.month”).append(“” + data[6].month + “”); $(“select.month”).append(“” […]

什么是AJAX以及它是如何工作的?

可能重复: AJAX如何工作? 注意 :这是一个社区维基post 我经常听说AJAX用于为用户提供动态内容。 它是什么以及它是如何工作的?

AJAX:提交表单而不刷新页面

我有一个类似于以下的表格: 我是AJAX的新手,我想要完成的是当用户点击提交按钮时,我想让mail.php脚本在后台运行而不刷新页面。 我试过类似下面代码的东西,但是,它仍然像以前一样提交表单而不是像我需要的那样(在幕后): $.post(‘mail.php’, $(‘#myForm’).serialize()); 如果可能的话,我想帮助使用AJAX实现这一点, 提前谢谢了

jQuery Ajax在php同一页面上传递值

当我试图在同一页面上发送价值时,我有点困惑。 $(“select[name=’sweets’]”).change(function () { var str = “”; $(“select[name=’sweets’] option:selected”).each(function () { str += $(this).text() + ” “; }); jQuery.ajax({ type: “POST”, data: $(“form#a”).serialize(), success: function(data){ jQuery(“.res”).html(data); $(‘#test’).text($(data).html()); } }); var str = $(“form”).serialize(); $(“.res”).text(str); }); Chocolate Candy Taffy Caramel Fudge Cookie 好吧,如果它位于html标签的顶部,它将显示,但如果它在体内,它将显示为null。

jquery ajax readystate 0 responsetext status 0 statustext error

我收到以下错误: jquery ajax readystate 0 responsetext status 0 statustext error给出它: url(http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm) ,但是当我给它url(localhost:””/embparse_page)时它工作正常url(localhost:””/embparse_page)我的localhost上的url(localhost:””/embparse_page) 。 我尝试使用我在Google搜索中找到的标题,我使用了beforeSend:”” ,但它仍然没有用。 我认为主要问题是: XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin “local server” is not allowed by Access-Control-Allow-Origin. XMLHttpRequest cannot load http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm. Origin “local server” is not allowed by Access-Control-Allow-Origin. 但我不明白。 任何人都可以向我解释这个问题,因为我对此很陌生。 Page Parsing getit=function(){ jQuery.support.cors = true; $.ajax({ type:”GET”, url:”http://www.tutorialspoint.com/prototype/prototype_ajax_response.htm”, dataType:”html”, crossDomain:true, beforeSend: function(xhr) […]

如何从jQuery.ajax()过滤返回的数据?

当使用jQuery.ajax()方法时,我正在努力过滤返回的数据以获得我所需要的。 我知道这很容易使用.load()和其他jQuery AJAX方法,但我需要特别使用.ajax() 。 例如,我知道这是有效的; var title = $(data).filter(‘title’); // Returns the page title 但是,如果我只想要id为“foo”的div的内容呢? var foo = $(data).filter(‘#foo’); // None of these work var foo = $(data).find(‘#foo’); // var foo = $(‘#foo’, data); // 理想情况下,我想要一个方法,我可以传递一个普通的jQuery选择器,它可以用于选择标题,div或jQuery可以选择的任何其他元素。 这样我就可以将任何字符串传入我自己的ajax函数 – 例如; myApp.ajax({ url: ‘myPage.html’, filterTitle: ‘title’, filterContent: ‘#main-content’ }); 任何帮助将不胜感激。

使用Jquery Ajax从Mysql中检索数据

list.php :一个简单的ajax代码,我只想显示Mysql表的记录: $(document).ready(function(){ var response = ”; $.ajax({ type: “GET”, url: “Records.php”, async: false, success : function(text) { response = text; } }); alert(response); }); Let jQuery AJAX Change This Text Get Records Records.php是从Mysql获取记录的文件。 在数据库中只有两个字段:“名称”,“地址”。 Name: Address: <?php while ($row = mysql_fetch_array($result)) { echo "”; echo “$row[1]”; echo “$row[2]”; echo “”; } ?> 此代码无效。

如何使用jQuery在PHP中创建级联下拉列表

我的数据库由国家和城市组成。 第一个案例 – 成功完成: 国家/地区列表在页面加载时在下拉框中填充 城市列表在页面加载的下拉框中填充 – 填充的城市列表基于默认国家/地区。 第二种情况 – 无法做到: 用户更改国家/地 城市列表将根据所选国家/地区进行更改 我知道我必须使用jQuery / Ajax。 我试过,但由于缺乏编程经验,我无法解决我的问题。 我的列表是从数据库而不是XML中获取的。 我只需要一个快速的解决方案,我需要保持简单和愚蠢。 我使用常规的PHP编码风格,而不是面向对象。 我该怎么做? 任何相关的资源将不胜感激。

chrome中的jquery ajax问题

我在我的页面上运行了以下jquery代码,在FF和IE中运行得很好,但是Chrome似乎很吓人…… 在FF和IE中进行调用,结果附加到div。 在chrome中,它在失败时调用ajaxfailed。 传递给AjaxFailed函数的XMLHttpRequest的状态代码为“200”,statusText为“ok”。 readystate是4,responseText被设置为我希望附加到div的数据..基本上从我可以看到它调用失败方法,但它没有失败..我尝试了get和post请求和它总是打破铬。 function getBranchDetails(contactID, branchID) { $.ajax({ type: “GET”, url: urlToRequestTo, data: “{}”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: branchDetailsSuccess, error: AjaxFailed }); } function branchDetailsSuccess(result) { $(“#divBranchControl”).empty(); $(“#divBranchControl”).append(” ” + result); $(“#branchDiv”).tabs(); } function AjaxFailed(result) { alert(“FAILED : ” + result.status + ‘ ‘ + result.statusText); }

使用同步ajax调用有什么缺点?

这个问题肯定可以应用于jQuery,但在这种情况下,我指的是Prototype。 在原型文档中,它说, 由于同步使用相当令人不安,并且通常味道不好,因此您应该避免更改此设置。 认真。 我不确定使用同步ajax调用有什么缺点。 似乎有许多实例必须等待调用返回(不使用特定的回调函数)。 例如,我目前使用Prototype的onSuccess, onFailure and onComplete来处理其余的代码。 但是,我使用的Web服务(所有内部)跨越大多数项目,我的任务是创建更多可重用的代码。 一个示例是返回客户属性的客户类。 一个简单的例子(请记住,我只显示基本function以保持简单): Customer = Class.create({ initialize: function(customerId) { new Ajax.Request(‘some-url’, { method: ‘get’, parameters: { customerId: customerId }, onSuccess: this.setCustomerInfo.bind(this) } }, setCustomerInfo: function(response) { //for the sake of this example I will leave out the JSON validation this.customerInfo = response.responseText.evalJSON(); } }); 因此,使用这个简单的类我可以在任何项目中执行以下操作来获取客户信息。 […]