weixin_33725270 2012-02-15 18:05 采纳率: 0%
浏览 49

使用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.

  • 写回答

1条回答 默认 最新

  • 关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序