使用jQuery / AJAX的API问题

时间:2011-03-10 16:20:15

标签: ajax api jquery

这是我第二天使用jQuery& AJAX。我已经做了尽可能多的googleing,因为我知道这样做。但是,由于不知道我在寻找什么,我迷路了。这非常接近工作,但我无法弄明白。

我正在尝试使用我公司的(“xyz”)API,当我将表单操作=网页的网址时,它将无效。

我已经在PHP中多次这样做了。 API URL是:

xyz.com/getdata.php?from=tt&isbn={variable_int}

有人可以帮我一把吗?

<form method="post" action="xyz.com/getdata.php" id="searchForm">
    <input type="text" name="isbn" placeholder="Search..." />
    <input class="myaccount" id="doSearch" name="doSearch" type="submit" value="Search" />
</form>

<div id="result"></div>

{literal}
<script>
  // attach a submit handler to the form
  $("#searchForm").submit(function(event) {

    // stop form from submitting normally
    event.preventDefault(); 

    // get some values from elements on the page:
    var $form = $( this ),
       term = $form.find( 'input[name="isbn"]' ).val(),
       url = $form.attr( 'action' );

    // Send the data using post and put the results in a div
//    $.post( url, { doSearch: "Search", isbn: term } ,
    $.post( url, { from: "tt", isbn: term } ,
    function( data ) {
          var content = $( data );
          $( "#result" ).html( content );
      }
    );
  });
</script>

非常感谢(提前)!

2 个答案:

答案 0 :(得分:0)

使用AJAX请求的跨域并不像看起来那么容易。

以下是您应阅读的有趣链接:http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

答案 1 :(得分:0)

我不确定,但如果你使用下面的字符串

  

xyz.com/getdata.php?from=tt&isbn= {variable_int}

发送数据的方法是“get”。表单使用方法“post”。我认为存在冲突。