Using jQuery to parse XML returned from PHP script (imgur.com API)

不羁的心 提交于 2019-12-01 12:40:12
var docname =  $('#doc').val();

Exactly where is this in your code and when will it be evaluated?
My guess is that it's executed either when the <script> tag has been parsed or you've wrapped it in a $(document).ready() handler. Either way it get's evaluated before the user has actually typed something into the input/text control and docname will therefore be '' or even null all the time. You want the script to fetch the value not until the user has pressed the submit button.
Try it with

$('#submit').click(function() {
  $.ajax({
    type: "GET",
    url: "img_upload.php",
    data: "doc=" + $('#doc').val(),
    dataType: "xml",
    success: parseXml
  });
  return false;
});

edit: Even better, make the data property an object and let jquery handle the escaping of the value.

data: {doc: $('#doc').val()}

It could be that you have not set the header in the php script - this should be your first line.

header('Content-Type: text/xml');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!