如果页面是使用PHP中的ajax加载的.页面加载后如何调用函数 [英] if a page is loaded using ajax from PHP. how to call a function if page is loaded
问题描述
我正在研究php + ajax.有人可以在后续过程中帮助我吗
i'm working on php + ajax. can somebody help me in following process
- 我做了两个div(一个包含manu,另一个是目标div,从菜单中加载页面)
- 我在terget div中加载了一个.
- 此表单使用php向数据库添加值.
- 由于数据已成功保存 ...在目标div中,因此下一页进行了响应
- 现在我想在文本显示为"数据保存成功"之后立即调用javascript函数.
- 此功能将用户带到下一个表格...
如果还有其他解决方案,请告诉我.谢谢你
- I made two divs (one contains manu, and other is target div, where pages are loaded from menu)
- i loaded a from in terget div.
- this form adds values to database using php.
- the next pages respondeds as data is saved successfully... in target div
- now i want to call a javascript function right after text appears "data is saved successfully".
- this function takes the user to the next form...
if there is any other solution please do let me know. thank you
推荐答案
您将像执行任何标准AJAX一样进行操作:
You would do it just like any standard AJAX:
设置AJAX成功调用函数,以检查PHP代码返回的任何状态代码.如果状态代码成功,则执行您想做的事情-在这种情况下,请调用Javascript函数.
set up the call back function for the AJAX success to check for any status code returned by the PHP code. If the status code is a success, then do what you want to -- in your case, call the Javascript function.
通常,使用某些Javascript库(例如jQuery的AJAX)会更容易:
usually it is easier to use some Javascript library, such as jQuery's AJAX:
http://api.jquery.com/jQuery.ajax/
查找成功(数据,textStatus,jqXHR)
,这是回调函数及其示例.
look for the success(data, textStatus, jqXHR)
which is the callback function and the examples there.
请注意,状态码404或200与您自己的状态码不同.您的状态码可以是作为AJAX调用内容返回的任何内容.通常,通常会返回200的状态代码,但这是HTTP的代码,而不是您的状态代码.
note that the status code 404 or 200 is different from your own status code. Your status code can be anything returned as the content of the AJAX call. Usually, a typical status code of 200 is returned, but that's the code for HTTP, not your status code.
这篇关于如果页面是使用PHP中的ajax加载的.页面加载后如何调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!