开发者

searching within text of api

I'm trying to use an api and I'm just learning how to actually implement an api using php, hopefully I'll learn to incorporate jquery. I know how to create a simple search feature through mysql and its data with php, but is there a way to create search withi开发者_Go百科n the api? with API, there's json/xml responses, and they're all strings, so I was wondering if the user was able to search those strings?

Thanks


First you have to send the json data to php via AJAX. Something like this:

  var request;
  function runAjax(JSONstring)
  {
    // function returns "AJAX" object, depending on web browser
    // this is not native JS function!
    request = getHTTPObject();
    request.onreadystatechange = sendData;
    request.open("GET", "parser.php?json="+JSONstring, true);
    request.send(null);
  }

  // function is executed when var request state changes
  function sendData()
  {
    // if request object received response
    if(request.readyState == 4)
    {
    // parser.php response
    var JSONtext = request.responseText;
    // convert received string to JavaScript object
    var JSONobject = JSON.parse(JSONtext);

    // notice how variables are used
    var msg = "Number of errors: "+JSONobject.errorsNum+
        "\n- "+JSONobject.error[0]+
        "\n- "+JSONobject.error[1];

    alert(msg);
    }
  }

You then can call the variable that javascript creates by calling the $_GET['json'] variable.

strstr($_GET['json'] , $whatEverYourSearchingFor);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜