Connecting Php with javascript - Stack Overflow

I am trying to make a plugin that people can place on their site to generate a form. I dont want to use

I am trying to make a plugin that people can place on their site to generate a form. I dont want to use an iframe to display the form but use javascript to generate it.

The problem is how do i connect the javascript and php together. My site is programmed in PHP.

I am trying to make a plugin that people can place on their site to generate a form. I dont want to use an iframe to display the form but use javascript to generate it.

The problem is how do i connect the javascript and php together. My site is programmed in PHP.

Share Improve this question edited Dec 19, 2010 at 16:42 Jakub 20.5k8 gold badges66 silver badges93 bronze badges asked Dec 19, 2010 at 16:18 sammvillesammville 3832 gold badges4 silver badges14 bronze badges 2
  • Do you mean you want to use Javascript to generate a form on any domain, using data generated by PHP from you own domain? – Harmen Commented Dec 19, 2010 at 16:25
  • yes!! that is what i want to do. Php brings the data from the database and supplies it to javascript whcih displays it. – sammville Commented Dec 19, 2010 at 16:30
Add a ment  | 

3 Answers 3

Reset to default 1

Your getting a liite mixed up, I think.

PHP runs on your server. This is the place where you fetch data from the database and create some form of html-response.

Javascript runs in the browser. It can't directly talk to your database.

iframe is a special html-element: Therfore it is passive and can't do anything like creating a form.

You have two ways:

  1. Create a PHP script which handles everything through plain HTTP-Requests. This is the "old school" way and requires a lot of page-reloading.
  2. Write most of the logic in javascript and let it municate to PHP/your database through AJAX. In this case. Have a look at jQuery which makes AJAX-requests (and a lot of other things) very easy.

One issue you will be faced with is 'Cross site Scripting' with Javascript / AJAX. You can read up on it a bit here:

http://snook.ca/archives/javascript/cross_domain_aj

Also, thinking your process through, you will need sufficient javascript code to create a 'widget' on any place, and have a way to municate BACK to your server (keep in mind PHP only runs local on your machine, so it cannot be used remotely in your javascript).

You will probably need to build a JSON API (google / stack search this if needed). And enable munication from your JAVASCRIPT to the API (don't think of it as to PHP, even tho php will be your API server side language).

Here is an example of a PHP JSON API (on youtube too):

http://www.youtube./watch?v=F5pXxS0y4bg

If you put PHP into JavaScript and someone implements this, PHP will pile on their server. So you just can't. You just need to put the form in your plugin.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744955126a4603147.html

相关推荐

  • Connecting Php with javascript - Stack Overflow

    I am trying to make a plugin that people can place on their site to generate a form. I dont want to use

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信