努力獲取Ajax帖子請求的相對路徑以拾取php文件。我沒有收到錯誤,只是沒有任何反應(yīng)。瀏覽了這個網(wǎng)站,但在Ajax相對路徑上找不到我理解的答案。仍然是一個新手。如果有人能用外行的術(shù)語解釋它,真的很感激。我正在嘗試從根文件“index.php”訪問php文件“search/search.php”(此文件包含Ajax請求)。當兩個文件位于同一目錄中時,這有效。文件結(jié)構(gòu)如下:JQuery 代碼片段:$(function() { $('form').on("submit", function(e) { e.preventDefault(); $('#error').text(""); // reset var name = $.trim($("#search").val()); if (name.match(/[^a-zA-Z0-9 ]/g)) { $('#error').text('Please enter letters and spaces only'); return false; } if (name === '') { $('#error').text('Please enter some text'); return false; } if (name.length > 0 && name.length < 3) { $('#error').text('Please enter more letters'); return false; } $.ajax({ url: 'search/search.php', method: 'POST', data: { msg: name }, dataType: 'json', success: function(response) { $(".content").html("") $(".total").html("") if(response){ var total = response.length; $('.total') .append(total + " Results"); } $.each(response, function() { $.each($(this), function(i, item) { var mycss = (item.Type == 1) ? ' style="color: #ffa449;"' : ''; $('.content').append('<div class="post"><div class="post-text"> ' + item.MessageText + ' </div><div class="post-action"><input type="button" value="Like" id="like_' + item.ID + '_' + item.UserID + '" class="like" ' + mycss + ' /><span id="likes_' + item.ID + '_' + item.UserID + '">' + item.cntLikes + '</span></div></div>'); }); }); } }); });});
1 回答

慕后森
TA貢獻1802條經(jīng)驗 獲得超5個贊
前導正斜杠僅表示“從文檔根目錄開始”,即文檔根目錄所在的位置。所以應(yīng)該是正確的。如果服務(wù)器無法找到該文件,那么一定有一些URL重寫發(fā)生是有道理的。index.php
/search/search.php
您只需將瀏覽器指向 .如果你得到一個404,你知道它與ajax無關(guān)http://localhost:8000/search/search.php
- 1 回答
- 0 關(guān)注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消