【问题标题】:Accessing an XML file stored in a PHP variable with jQuery使用 jQuery 访问存储在 PHP 变量中的 XML 文件
【发布时间】:2014-03-15 01:03:51
【问题描述】:

我是编程新手,所以请放轻松=]

我正在使用以下 PHP 将用户的字符串发送到 API。 API 发回一个 XML 文件,我将它存储在$response 下。到目前为止,一切都很好。 现在,我正在头疼,如何根据 XML 上的数据触发 jQuery 函数。

如下所示,我正在访问$response -> success,如果success == 1 我想触发一些jQuery 函数,如果success 等于任何其他数字,我想触发一些其他jQuery 函数。我该怎么做?有可能吗?

if(isset($_POST['user_string']) == 5){ 
    $post = 'data='.$data.'&key='.$key.'&format='.$format.'&mode='.$mode;
    $url = 'api2.apisite.com.';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    curl_close($ch);

    if ($response -> success == 1) {

    } else {

    }

非常感谢!

【问题讨论】:

    标签: javascript php jquery ajax xml


    【解决方案1】:

    您提供的 PHP 示例是一个服务器端调用。 jQuery(通常)是客户端调用。

    不要将表单直接发布到 .php 文件,而是使用 jQuery.ajax() 或 jQuery.post() 来获取 .php 文件,将“user_string”作为 POST 数据传递。 jQuery.ajax() 然后可以检查 Ajax 响应的返回值并采取相应的行动。

    【讨论】:

      猜你喜欢
      • 2014-05-14
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 2012-03-29
      • 1970-01-01
      相关资源
      最近更新 更多