简体   繁体   English

如何在不刷新父页面的情况下从jquery打开“获取” php窗口?

[英]How do I open a “get” php window from jquery without a parent page refresh?

I know the question itself may seem a little vague. 我知道问题本身似乎有点含糊。 Let me elaborate. 让我详细说明。

I am trying to post data to a php file from a page controlled by jquery. 我正在尝试将数据从jquery控制的页面发布到php文件。

Here is what I have on the jquery end: 这是我在jquery端的内容:

var openURL = "http://derp.com/restr/js/addfood.php?fname=" + encodeURI(food_n) + "&fcals=" + encodeURI(food_c);
window.open(openURL);

The Problem is not that it wont go to the page, the problem is that the parent page reloads once the code is executed. 问题不在于它不会转到该页面,而是在于一旦执行了代码,父页面就会重新加载。 Is there any way to keep this from happening? 有什么办法可以防止这种情况发生?

You need to look into using jQuery's ajax() methods . 您需要研究使用jQuery的ajax()方法 They have special functions that will run when data from your PHP script is loaded, without refreshing the page. 它们具有特殊功能,这些功能将在加载PHP脚本中的数据时运行,而无需刷新页面。

The basic idea is to use something like... 基本想法是使用类似...

$.ajax({
  url: "file_to_load.php",
  data: {},
  success: function(data){
    //it worked!
    alert(data);
  }
});

...using the data object to hold your get or post params. ...使用data对象保存您的get或post参数。

I believe your only options is to reload the content into the current page. 我相信您唯一的选择是将内容重新加载到当前页面中。 In other words, the entire second page has to replace the original via ajax. 换句话说,整个第二页必须通过ajax替换原始页面。 Depending on where you want the performance, you could either load the entire second page with "display:none;" 根据需要的性能,可以使用“ display:none;”加载整个第二页。 off the bat, minus the new content, Then add that in after the ajax. 立即删除新内容,然后将其添加到ajax之后。 Or pass the "new page," of course minus anything that doesn't change, with ajax and replace accordingly. 或通过ajax传递“新页面”,当然减去所有不变的内容,并相应地进行替换。

I haven't mastered ajax inside and out, so there possibly be another method, but I've sure never heard of one. 我还没有完全掌握ajax,所以可能还有另一种方法,但是我确定从未听说过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从PHP的子窗口刷新父 - how to refresh parent from child window in php 我如何在没有页面刷新的情况下使用 ajax/jquery 在我的弹出表单框中显示 php 错误消息 - How do i showing php error message on my popup form box with ajax/jquery without page refresh 如何在不重新加载页面的情况下重置 Bootstrap 模式窗口? 使用 PHP、jQuery、AJAX - How do I do a reset of the Bootstrap modal window without reloading the page ? Using PHP , jQuery, AJAX 关闭PHP中的弹出窗口时,如何刷新父页面上的表? - How to refresh a table on the parent page when I close a popup window in PHP? 我如何在加载时打开此模式窗口-PHP - How do I get this modal window to open on load - PHP 我如何通过jQuery在DIV中显示PHP回声而无需刷新页面 - How can I show PHP echo in DIV through jQuery without page refresh 如何使用jQuery和PHP动态更新分数而无需刷新页面 - How to update score dynamically using jquery and php without page refresh 如何在不刷新页面的情况下发布数据(窗体)PHP,jQuery,Ajax - How to post data (form) without page refresh PHP, jQuery, Ajax 如何使用JQUERY排序PHP循环而无需刷新页面 - How to sort PHP loop without page refresh using JQUERY 如何在不刷新页面的情况下从另一个页面触发jquery函数? - How to fire a jquery function from another page without page refresh?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM