使用JSON连接两个文件

Here I have a two files. One for forms and second php for getting results...

PHP file:

$site=$_GET['textfield1']
$xpathfromform=$_GET['textfield2']


$dom = new DOMDocument();
@$dom->loadHTMLFile($site);
$xpath = new DOMXPath($dom);
$result = $xpath->query($xpathfromform)->item(0)->textContent;

second file is a form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<label>Enter URL address here: 
<input name="textfield" type="text" value="http://www." />
</label>
<label>
<input type="submit" name="Submit" value="Submit" />
<br />
<br />
Enter xpath location of element:
<input type="text" name="textfield2" />
<input type="submit" name="Submit2" value="Submit" />
<br />
<br />
Selected element is: </label>
<p>&nbsp;</p>
</body>
</html>

How to connect this two files with JSON... example what I need:

1st. type URL and then xpath and click on submit 2nd. when I click I need to start .php file to get result 3th. I must get $result from php file and show in my first file ...

How to connect this two files with json ??? or something else.

Man, you need to do questions with a bit more sense O.o

So, are you trying to make an AJAX request to your php "file" when the submit button is pressed?

If yes, follow these steps:

  1. Add a listener to the submit event for you form $(form).submit(ajaxSubmit) when ajaxSubmit is a function that will receive an event as parameter
  2. In ajaxSubmit will be some steps:

    • Make sure that the default event (form submit) will not happens event.preventDefault()
    • If you need, validate the form fields.
    • Serialize your fields and call $.ajax with your parameters and handling a success function
  3. The ajax success function, get the result and write it into some element on form page.

So, see an example of ajax form submit and handling JSON response